Jump to content

Recommended Posts

Hi everyone,

I'm having issues communicating with a balance over RS232 on a Samba 3.5.  I can send commands with no issues from the plc to the balance but cannot seem to receive messages.  I believe it's in the way I have the formatting set up in the scan protocol.  I was hoping someone could lead me in the correct direction.

From the manufacturer, the message I should be receiving from the balance is in the form of:  S_S_##########_gCrLf    where _ is  a space, # is a number, Cr is a carriage return, Lf is a line feed.  I used a terminal program and verified that it will return a message like this just without the Cr and Lf displayed.

All I want to pull out of this message is the 10 # values.  If the balance does not use all 10 values, it will use a leading space.  It is also possible to have a negative sign leading the number.  Some examples of what I could receive are: S_S_ _ _ _ _ _11111_g       or   S_S_ _ _ _ _ -11111_g  .     It's also possible I can receive S_D_ instead of S_S_ but I think I can handle this through a second scan?

I attached a picture of how I have the scan block set up currently.  I've been trying little modifications for over a day now so any help would be great.

Thanks!

 

RS232 Comm.jpg

Link to comment
Share on other sites

  • MVP 2023

The string format in the Scan function block only works if the string is guaranteed to have the same format every time.  Yours does not, so you need a different method.

The proper way to do this is to use one massive stream variable and then strip off what you don't need using the string function blocks.  If you'll post your .vlp code I'll make some modifications to get you started and put it up.

Joe T.

Link to comment
Share on other sites

Thanks, I ended up doing exactly that.  I have it streaming 16 ASCii values to 16 MI addresses.  I'm then taking and converting the ASCii values that correlate to the ones, tens, hundreds, thousands, and ten thousands spots and converting them to numeric.  Then I'm adding all those together to get one overall numeric that I can store to a single MI address.

I have a new issue however and I'm not sure if it's on the PLC side of things or the balance.  I currently have a timer set for 1s.  When the timer comes true, the PLC sends a request to the balance.  My scan block follows COMS aren't busy.  Then my ASCii to numeric conversions are done.  Finally I reset my buffer when session is complete.  This works for a period of time but randomly the value will increase by a factor of 10 or a factor of 100.  It's almost as if my MI registers are shifting over a spot for a split second so instead of multiplying my tens spot by 10, I multiply by 100.  I'm leaning towards a balance issue but I'm wondering if it could be part of my code where the buffer is not clearing.

Link to comment
Share on other sites

  • MVP 2023

I'd slow your timer down to 10 sec or more so you can see what's going on.  I also always include a Copy Buffer block and select another MI area to look at the last buffer value. 

A little-know secret in Visilogic is the Memory tab at the bottom.  Enter the beginning register of your copied buffer, set the length, Size 8 bit, and Format ASCII.  You'll be able to see your buffer data in readable form.

Troubleshoot your code from there.

Joe T.

  • Upvote 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.