Page 3 of 3
Re: RS232 / Serial Scale Help
Posted: Saturday 11th September 2021 7:22pm
by AndyGable
Hi @thatbruce
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
Public Sub btnRequestWeight_Click()
RS232Scanner.EndOfLine = gb.mac ' Trust me, I am an expert
Write #RS232Scanner, "S11\n"
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
*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
Sleep 0.025
Try Read #RS232Scanner, Global.ScannerData, Lof(RS232Scanner)
If Error Then
Print "Error With Incoming Serial Data\n";; Error.Text
Endif
If Len(Global.ScannerData) > 2 Then
Print "Raw Barcode Number : " & CStr(Global.ScannerData)
CleanUpBarcodeData(CStr(Global.ScannerData))
Endif
If you know of a better why I am more then willing to see what you would do (best way to learn)
Re: RS232 / Serial Scale Help
Posted: Sunday 12th September 2021 12:31am
by thatbruce
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
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.
Try this version
Code: Select all
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
*I had to update the Endofline to work with my RS232Scanner steam
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.
Re: RS232 / Serial Scale Help
Posted: Sunday 12th September 2021 9:07pm
by AndyGable
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"
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
If Not Global.ScaleData Then
Print "Error With Incoming Serial Data"
Else
Print "Raw Scale Weight : "; Scan(Global.ScaleData, "S11*")[0]
Endif
End
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
this is just to show you I am getting data from the scanner side (so the scanner/scale is communicating to the Computer)
Re: RS232 / Serial Scale Help
Posted: Sunday 12th September 2021 11:17pm
by thatbruce
Woah! Where'd that
Write #RS232Scanner, "S14\n"
come from?
Re: RS232 / Serial Scale Help
Posted: Monday 13th September 2021 12:51pm
by AndyGable
Sorry according to the C program it was needed (I must have forgotten to remove that before sending it to you)
Re: RS232 / Serial Scale Help
Posted: Monday 13th September 2021 5:51pm
by thatbruce
AndyGable wrote: ↑Sunday 12th September 2021 9:07pm
this is just to show you I am getting data from the scanner side (so the scanner/scale is communicating to the Computer)
No, AFAICT it tells me that you are getting data from the
scanner unit and not particularly the scanner
and the scale.
Get this manual
https://manualzz.com/download/1055726 if you dont already have it and go through section 5, scanning each of the relevant looking barcodes, IOW lets find out if the damn scale
unit is actually working. In fact it might be good idea to go through the entire bloody manual.
Ok, that's enough of the hardware for a moment.
Back to the software!
First lets get rid of this one: (I'm only writing this to make sure we are operating on the same wavelength here.)'
Code: Select all
Write #RS232Scanner, "S11\n"
Write #RS232Scanner, "S14\n"
is equivalent to "Hey scale, whats the weight? NO STOP DOING THAT and do a 4!" (Whatever a 4 is, its not in any Datalogic "manual" that I can find.)
Anyway, lets try this way. This time I just want to wait till
anything at all is received back from the unit.
Code: Select all
Public Sub btnRequestWeight_Click()
Dim iBytes as Integer
Dim sWhatever as String
RS232Scanner.EndOfLine = gb.mac
RS232Scanner.Blocking = True
Write #RS232Scanner, "S11\n"
' Wait for anything at all to be sent back.
Do
Wait 0.001 ' Using a really small delay this time to lessen overflow risk
sWhatever &= Read #RS232Scanner As Byte ' I hope this works, I've not tried appending bytes to a string "buffer" before.
Print "Got ";Len(sWhatever);"from scanner" ' Just output the length of the receiving buffer
Loop Until #RS232Scanner.Eof ' Keep going until we get an eof char. YOU MAY HAVE TO KILL IT AGAIN HERE.
' I'm not going to try and decipher the response message ATM until we can at least prove we got anything back.
End
Re: RS232 / Serial Scale Help
Posted: Monday 13th September 2021 11:39pm
by AndyGable
Public Sub btnRequestWeight_Click()
Dim iBytes as Integer
Dim sWhatever as String
RS232Scanner.EndOfLine = gb.mac
RS232Scanner.Blocking = True
Write #RS232Scanner, "S11\n"
' Wait for anything at all to be sent back.
Do
Wait 0.001 ' Using a really small delay this time to lessen overflow risk
sWhatever &= Read #RS232Scanner As Byte ' I hope this works, I've not tried appending bytes to a string "buffer" before.
Print "Got ";Len(sWhatever);"from scanner" ' Just output the length of the receiving buffer
Loop Until #RS232Scanner.Eof ' Keep going until we get an eof char. YOU MAY HAVE TO KILL IT AGAIN HERE.
' I'm not going to try and decipher the response message ATM until we can at least prove we got anything back.
End
I am sorry to say not a thing on that code either
I even tried to send a simple "S334\n" command (should make the scanner just bleep) but eben that did not work.
COULD all this issues be becuase I am opening as incoming only? (like from device to Computer and no both way communcation or is 2way the default for the comport in gambas?)
Re: RS232 / Serial Scale Help
Posted: Tuesday 14th September 2021 2:53pm
by thatbruce
I even tried to send a simple "S334\n" command (should make the scanner just bleep) but eben that did not work.
COULD all this issues be becuase I am opening as incoming only? (like from device to Computer and no both way communcation or is 2way the default for the comport in gambas?)
I don't know why the Write's didn't raise an error, but if you don't open FOR READ WRITE then nothing should be sent, so nothing could happen. There will be silence ... and by the way it's not the comport your code is talking to, its the gambas runtime and then some shared libraries and then the operating system and only then the com port (UART). IOW gambas has no concept of a comms port only a stream.
Re: RS232 / Serial Scale Help
Posted: Tuesday 14th September 2021 3:15pm
by AndyGable
I'm using
RS232Scanner.open
Do I need to do it like
open RS232Scanner for read write