RS232 / Serial Scale Help
Posted
#1
(In Topic #739)
Enthusiast

I need some advice
I am trying to get a scanner scale to send the weight to my application (I can get the barcode number with no problem)
I was sent this by the Manafactor
Single Cable:
RS232 Parameters: 9600, Odd, 7, 1, (recommended) - No software control
Weight Request: STX, Address, FC, ETX, BCC
STX = ASCII S (83 dec, 53 hex)
Address = ASCII 1 (49 dec, 31 hex)
FC (function code) = ASCII 1 (49 dec, 31 hex)
ETX = ASCII CR (13 dec, 0D hex)
BCC = Optional
Weight Format: STX, 1, 1, xxxxx, ETX, BCC
Scale Cancel (optional - dependent on POS s/w): STX, 1, 2, ETX
So working from this I have come up with this code
Code
Public STX As String = Chr(&H53)
Public Address As String = Chr(&H31)
Public FunctionCode As String = Chr(&H31)
Public ETX As String = Chr(&H0D)
Public Sub btnRequestWeight_Click()
Write #RS232Scanner, STX & Address & FunctionCode & ETX
Sleep 0.025
Try Read #RS232Scanner, Global.ScaleData, Lof(RS232Scanner)
If Error Then
Print "Error With Incoming Serial Data"
Else
Print "Nothing from Scale"
Endif
If Len(Global.ScaleData) > 0 Then
Print "Raw Scale Weight : " & CStr(Global.ScaleData)
' CleanUpBarcodeData(CStr(Global.ScannerData))
End If
End
but I keep getting the Error Mesage "nothing from Scale" print
am I doing something wrong? any help or gidance would be most welcomed
Posted
Regular

Code
Try Read #RS232Scanner, Global.ScaleData, Lof(RS232Scanner)
If Error Then
Print "Error With Incoming Serial Data"
Else
Print "Nothing from Scale"
EndifIf it is printing "Nothing from scale" then there is no error, i.e. the Read worked.
Posted
Enthusiast

I have even tried to send the Commands
Write #RS232Scanner, "S11\r"
Write #RS232Scanner, "S14\r"
But the scale still refuses to do anything (the scanner is still sending data to the PoS And this is on the same port)
Posted
Regular

At the
Code
If Len(Global.ScaleData) > 0 Thenb
Posted
Enthusiast

Posted
Guru

I've seen issues using Sleep not Wait.
I've seen issues using CStr() not Str() to get values?
actually, looking at it, the Read command should read to a String variable
Global.ScaleData should be a string , so CStr() is not needed. CStr converts a non string value to a String,
Does the Write command need a terminating Linefeed?
Are you receiving ANY info from the device using Read? Ie, you are sure the com link is working.
Posted
Guru

Code (gambas)
Posted
Enthusiast

BruceSteers said
I have no clue but..
I've seen issues using Sleep not Wait.
I've seen issues using CStr() not Str() to get values?
actually, looking at it, the Read command should read to a String variable
Global.ScaleData should be a string , so CStr() is not needed. CStr converts a non string value to a String,
Does the Write command need a terminating Linefeed?
Are you receiving ANY info from the device using Read? Ie, you are sure the com link is working.
Yea I can get the barcodes from the device (it is a combined scanner / scale unit) and it sends the Barcode number out with no problem
Posted
Enthusiast

BruceSteers said
I'd write it like this…Code (gambas)
Just tried that and I am sorry to say still nothing coming from the scale
Not sure if this will make a differance but this is my code i am using to open the comport (I asuume it is open to talk both ways)
Code (gambas)
- 'Set up the Serial Device so it should start talking
- With RS232Scanner
- .PortName = "/dev/ttyS0"
- .Speed = "9600"
- Global.AddToListBox("Sorry Unable to connect to Scanner\nPlease check settings and try again")
- Global.AddToListBox("Ready to scan barcode")
Posted
Guru

looking at the page /comp/gb.net/serialport - Gambas Documentation it has a number of other Events
Note: the below method is expecting the device to send text strings not binary values.
Code (gambas)
- Global.AddToListBox("Sorry Unable to connect to Scanner\nPlease check settings and try again")
- Global.AddToListBox("Ready to scan barcode")
- ' you may need to enable watching...
- ' Attach the stream to "Scanner" in this class.
- ' Then add a read event method for Scanner (Ps, there are other events listed)
- ' PS. Sorry i was wrong about using Read giving a String. Using stream.ReadLine() gives a string Read is binary :-\
- sData = RS232Scanner.ReadLine()
- Print "Recieved from Scanner:";; sData
I'd say your problem is probably either read/write is not set up properly or the command being sent is not the right format.
It's very very difficult for us to guess your problem with tiny snippets of code and none of us having the device you have.
I'd say you need the following..
More study on the differences between vb code and other examples you're finding and gambas code so your conversions look better.
More study on opening/reading/writing/watching streams
a bit more research to find some example code that uses your device. any programming language code should help give insights into the correct operation of the device.
Does it need a LF?
Write #RS232Scanner, STX & Address & FunctionCode & ETX & gb.Lf
Do the commands need to be sent individually?
Write #RS232Scanner, STX
Write #RS232Scanner, Address
Write #RS232Scanner, FunctionCode
Write #RS232Scanner, ETX
You are just going to have to play around with it till you crack it
PS. I do not have a device to test the above code so have no idea if it will work , it's just an example.
Posted
Regular

At the
Code: Select all
If Len(Global.ScaleData) > 0 Then
line have you inserted a breakpoint and inspected the value of the Global and the value of Global.ScaleData?
is the answer to a different question. Printing something and inspecting something are not the same.I have done a print to the debug console and it is empty
Posted
Enthusiast

thatbruce said
@BruceS, Yes I was going to suggest the same but I still haven't got an answer from AndyGable to my questionAt the
Code: Select all
If Len(Global.ScaleData) > 0 Then
line have you inserted a breakpoint and inspected the value of the Global and the value of Global.ScaleData?
AndyGable ,
is the answer to a different question. Printing something and inspecting something are not the same.I have done a print to the debug console and it is empty
Hi
the Global.ScaleData is empty nothing is being placed into it
Posted
Regular

Going back to your original post :
You appear to be setting STX, which I presume is the ANSI "start transmission" character, to &H53. But 53 is the printable "S" character ?
STX is $H02
Any reason for this discrepancy?
Also, according to your "Manafactor" ETX is a "CR" character, &0D which is a bit strange. But if they really mean it then ok.
Their REQUEST string is "Weight Request": STX, Address, FC, ETX, BCC where the BCC is optional (and is a low level and I mean UART level character added to the TX sequence).
So you should be sending (in hex):
02;31;31;0d
of which I find that 0D a bit weird in that why does it need a C/R and no ETX
Can you post a link to that "Manafactor" document.
b
Posted
Regular

<LIST>
- <LI>Your program is using a Write command to send a request to the scale.</LI>
<LIST>
- <LI>Your program waits a little while</LI>
<LIST>
- <LI>It then attempts to get the scale's response using a Try Read construct</LI>
Now this read succeeds because it <COLOR color="#FF0000">almost always will*</COLOR>. By using Try Read you are essentially saying "Check for any data in the buffer and if so, stick it in Global.ScaleData". So the command will always work, there will be no error. Thus the "If Error" part will never happen and the "Else" part always will.
<LIST>
- <LI>Your program then tests to see if the Read actually found some data.</LI>
As you say, it doesn't
Hence the above post.
* The only example I can think of is when someone runs away with the scale exactly during your Sleep pause.
Posted
Enthusiast

thatbruce said
Hoowee. We are really going to have to go back to basics here.
Going back to your original post :
You appear to be setting STX, which I presume is the ANSI "start transmission" character, to &H53. But 53 is the printable "S" character ?
STX is $H02
Any reason for this discrepancy?
Also, according to your "Manafactor" ETX is a "CR" character, &0D which is a bit strange. But if they really mean it then ok.
Their REQUEST string is "Weight Request": STX, Address, FC, ETX, BCC where the BCC is optional (and is a low level and I mean UART level character added to the TX sequence).
So you should be sending (in hex):
02;31;31;0d
of which I find that 0D a bit weird in that why does it need a C/R and no ETX
Can you post a link to that "Manafactor" document.
b
That information I posted on the first page was the document I was sent by Datalogic
i know foe 100% that the scale works as it works with my windows PC and my windows software
Posted
Enthusiast

Dual Cable (SASI):
RS232 Parameters: 9600, Even, 7,1 - No Flow Control
Weight Request: ASCII W (87 dec, 57 hex)
Weight Format: STX, xx.xxx, CR
Dual/Single Cable (ICL):
RS232 Parameters: 2400, Even, 7,1 - works with ACK/NAK
Weight Request:
1. Enquire (scale status): ASCII ENQ (05 dec, 05 hex)
Answers:
Error = NAK
Weight Not Stable = NUL (00 dec, 00 hex)
Weight OK = ACK (06 dec, 06 hex)
2. Data Request: ASCII DC1 (17 dec, 11 hex)
Answers:
Error = NAK (05 dec, 05 hex)
Data = STX, Status, xxxxx, BCC, ETX
Single Cable:
RS232 Parameters: 9600, Odd, 7, 1, (recommended) - No software control
Weight Request: STX, Address, FC, ETX, BCC
STX = ASCII S (83 dec, 53 hex)
Address = ASCII 1 (49 dec, 31 hex)
FC (function code) = ASCII 1 (49 dec, 31 hex)
ETX = ASCII CR (13 dec, 0D hex)
BCC = Optional
Weight Format: STX, 1, 1, xxxxx, ETX, BCC
Scale Cancel (optional - dependent on POS s/w): STX, 1, 2, ETX
To do this in Hyperterminal you need to do it via sending a text file.
So to send STX do an alt function 002,S11,Enter,Alt Function 003
Or do via another program that sends data in Hex
test in com test serial single cable option.
send the following command to get weight, then put the weight on.
\x53\x31\x31\x0D
A comtest session is saved in the FRS folder for RS232 SC Host command examples.
Posted
Guru

send the following command to get weight, then put the weight on.
\x53\x31\x31\x0D
Well i wish you'd posted that in the first post.
I'm not sure what it means but i bet the other Bruce has a pretty good idea after seeing their example of sending the command.
far easier to understand than "what are you doing wrong"
did you try
Write #RS232Scanner, "\x53\x31\x31\x0D"
Posted
Regular

Hey man, it took me three whole days to set up the GF's cash register in the pub. The people who write these POS manuals really should be taken out and horsewhipped. This is why I'm trying to go through this step-by-step (and keep asking what seems to be inane questions like what follows).I'm not sure what it means but i bet the other Bruce has a pretty good idea after seeing their example of sending the command.
far easier to understand than "what are you doing wrong"
Andy,
1) What connector types are involved at your computer end here, DB25, DB9, USB, RSJ45, RSJ65?
That may seem a ridiculous question, but DataPoint use different software protocols (at the application message level) for different cables.
2) That file they sent you is self-contradictory and basically looks like something that was thrown together randomly.
a) "Weight Request: STX, Address, FC, ETX, BCC" - Let's assume that is the correct request for your scale and cables.
A bit of a look through a couple of datapoint manuals reveals that the STX character used by the scale is actually <COLOR color="#FF0000">programmable</COLOR>. So we need to find out what is is for the scales in question (or reset them). Also if you look at the schematics of these POS systems you will find that each component has its own processor, IO controller and UARTS in it. So whats good for the barcode scanner may not be the same for the scales (or the display etc). However, lets assume that for your scales the STX character is &H53 (the "S" character). Which
- makes their
line bullshit. (But it might be a half-garbled bit of "Hyperterminal" text and so is absolutely useless here.)So to send STX do an alt function 002,S11,Enter,Alt Function 003
c) So looking at a couple of their technical specs it does appear that some, but not all, of their scales do have a default STX value of "S". Sheesh. Some comms programmers need horsewhipping as well.
Can you determine what the STX character really is for your test scales?
Are you trying to program for only one scales model, or multiple. If the latter we are going to have to find out how to query the damn things to get the STX character they are using.
My brain is starting to hurt and we have only looked at one character in the stream
b
Posted
Enthusiast

I totally agree with you on the user manals for Point of sale hardware they are not done very well at all
I have the fun job of converting over from Windows the Printer, Cash drawer and card processing modules (they are NOT going to be fun but I have a example of the cash drawer status support in FreeBASIC) The hard part is going to figure out how the Printer status data
anyway in replay to your requests please see below
- I am using a DB9
- That was the only thing I received from Datalogic (I do have access to a C app that was designed to work with the scanner / scale but i'm being told it is not complete
3) Can you determine what the STX character really is for your test scales? I would have to look at the documents and come back to you on that one
4) I am going to use a Module per scale (but Datalogic is saying the wight command should work for all thier Scanner / scales ranges)
My brain is starting to hurt and we have only looked at one character in the stream
Posted
Regular

Another side-ways question: Is there a device access controller (DAC or sometimes EAC, LAC or DCU <COLOR color="#BFFFFF">or even FIIK</COLOR> depending on the POS brand)? Because if so we may need to find out how to talk to it rather than the individual parts.
Regardless of that, good a DB9 connector usually means we are dealing with a fairly basic electronics system. By basic I mean they tend to follow the old serial comms protocols.
… hmmmm thinks
BINGO! I now see what this STX = "S" crapola is all about (and why there is no proper ETX). They are only talking about the message content, but <COLOR color="#FF0000">they are using flow control terms to describe it</COLOR>. :evil: :evil: :evil: Right, the conversation is fundamentally:
Code
Computer sends "Weight Request" -> Operator puts item on scale -> Scale measures weight -> Scale sends "Weight Format"But assuming everything is tickety-boo. Lets look at what I think they really mean.
The "Weight Request" message sent by the computer in one burst is :
Code
["Hey POS"]["Connect me to the scales"]["Hey scales, do a '1' function"]["That is all" and stops talking]Code
[ STX ][ Address ][ FC ][ ETX ] or
[ S ][ 1 ][ 1 ][ C/R ](miracle occurs here. The scale figures out it has something on it, measures its weight and sends a message back to the computer.)
The "Weight Format" message you should get is :
Code
[ STX ][ Address ][ FC ][ xxxxx ][ ETX ] or
[ S ][ 1 ][ 1 ][ <the weight I guess> ][ C/R ]Read #RS232Scanner, Global.ScaleData, Lof(RS232Scanner) is giving an empty string instead of "S11xxxxx\n" then something is very wrong somewhere.
Let's try something silly…
Code
Public Sub btnRequestWeight_Click()
Stream.EndOfLine = gb.Mac ' Trust me, I am an expert
Write #RS232Scanner, "S11\n"
LineInput #RS232Scanner, Global.ScaleData
If Not Global.ScaleData Then
Print "Error With Incoming Serial Data"
Else
Print "Raw Scale Weight : "; Scan(Global.ScaleData, "S11*")[0]
Endif
EndWhat happens?
b
Posted
Enthusiast

I copied your code and I got a error saying End of file in FMain:108 and it is heighlighting the line Line Input #RS232Scanner, Global.ScaleData
Code (gambas)
- RS232Scanner.EndOfLine = gb.mac ' Trust me, I am an expert
- Write #RS232Scanner, "S11\n"
- Line Input #RS232Scanner, Global.ScaleData
- Print "Error With Incoming Serial Data"
*I had to update the Endofline to work with my RS232Scanner steam
This is what I am using to read the barcode from the scanner side
Code (gambas)
If you know of a better why I am more then willing to see what you would do (best way to learn)
Posted
Regular

Good! Now we are getting somewhere. It looks like there is nothing in the input buffer as the Line Input is not waiting for some data.I copied your code and I got a error saying End of file in FMain:108 and it is heighlighting the line Line Input #RS232Scanner, Global.ScaleData
Try this version
Code
Public Sub btnRequestWeight_Click()
RS232Scanner.EndOfLine = gb.mac
RS232Scanner.Blocking = True
' From the wiki: When this property is set, reading from the stream will block if there is nothing to read
Write #RS232Scanner, "S11\n"
' Take little naps for a while to let anything happen like de operator putting de bananas on de scales
While not Eof(#RS232Scanner)
Wait 0.25 ' zzzz for 1/4 sec
Wend
' TODO: If that loops forever, then I'm wrong. Let me know.
Line Input #RS232Scanner, Global.ScaleData
If Not Global.ScaleData Then
Print "Error With Incoming Serial Data"
Else
Print "Raw Scale Weight : "; Scan(Global.ScaleData, "S11*")[0]
Endif
End
Ah, yes. I did wonder whether the static version would work in this situation. Don't forget I'm working blindly here, the only serial device at this location is me, so I can't check the code I'm posting. Also, the code "should be" atomic and you shouldn't have to make changes elsewhere to get it to work. So if other things break, undo it (use a dedicated branch for this stuff and use git revert? (or whatever it is)) and tell me.*I had to update the Endofline to work with my RS232Scanner steam
Posted
Enthusiast

Code (gambas)
- RS232Scanner.EndOfLine = gb.mac
- ' From the wiki: When this property is set, reading from the stream will block if there is nothing to read
- Write #RS232Scanner, "S11\n"
- Write #RS232Scanner, "S14\n"
- ' Take little naps for a while to let anything happen like de operator putting de bananas on de scales
- 'While Not Eof(RS232Scanner)
- ' Wait 0.25 ' zzzz for 1/4 sec
- 'Wend
- ' TODO: If that loops forever, then I'm wrong. Let me know.
- Line Input #RS232Scanner, Global.ScaleData
- Print "Error With Incoming Serial Data"
Hi thatbruce,
I tired your code and the app just sits there doing nothing if I Step though the code it just sits on the
Line Input #RS232Scanner, Global.ScaleData Line
And yes I had to comment out the loop command otherwise It was just in the loop for ever
<IMG src="https://support.algpos.co.uk/images_help/barcodeReader-incoming.png">
</IMG>this is just to show you I am getting data from the scanner side (so the scanner/scale is communicating to the Computer)
Posted
Regular

come from?Write #RS232Scanner, "S14\n"
Posted
Enthusiast

1 guest and 0 members have just viewed this.


