I am trying to read from a set of Kern scales that produce the following 18 byte stream.
Byte 1: Hex00 (or 01, 02 03 04 05)
Bytes 2 to 5 : HEX20 (Space)
Bytes 6 to 12 : Numeric data to be extracted
Byte 13 : HEX20 (Space)
Byte 14 : HEX67 (g)
Bytes 15,16 :HEX20 (Space)
Bytes 17,18 : CR+LF
I read that SerialInRecord will only work if the first character is fixed so have reverted to SerialIn and Mid to extract the data. This works but it regularly misses scans. This is one of the many versions that I've tried.
Public Weight As String * 19
Public edit1 As String * 7
Public floatweight As Float
DataTable(Table1,True,-1)
DataInterval(0,5,Sec,0)
Sample(1,Weight ,String)
Sample(1, floatweight, Float)
EndTable
'SequentialMode
BeginProg
Scan(5,Sec,1,0)
SerialOpen(ComC5, 9600, 0, 0, 19)
SerialFlush(ComC5)
SerialOut(ComC5, "w"&CHR(13)&CHR(10), "", 1, 0)
SerialIn(Weight,ComC5,100,CHR(10),19)
edit1= Mid(Weight,6,7) 'extract data
floatweight = edit1 'convert to floating point
SerialClose(ComC5)
CallTable Table1
NextScan
EndProg
Any assistance would be appreciated.
SerialInRecord() could be used with 0 as the BeginWord parameter, and using a value for the number of bytes to read in before the EndWord. If you switched to SerialInRecord, you would need to add a delay.
Suggestions:
(1) Watch in the datalogger terminal to see how much time the scale takes to respond to the command. That would let you refine the delay needed.
https://www.campbellsci.com/videos/sdi12-sensors-watch-or-sniffer-mode
(2) Use format 3 in SerialOpen(). That first byte is messing you up. With format 0, that first byte is dropped if unprintable.
I finally had some time to try again and the sniffer mode is very useful. I hadn't previously noticed that the scale's display dims when connected to the logger (and that they switch off when hot plugged). Unfortunately this probably indicates that they are not particularly happy with the TTL levels used for the RS-232 (CR800:C1,C2) as this does not happen with a genuine RS-232 connection. I'll revert back to using a separate bit of software for the scales. The SDM-SIO1A would probably solve this but I have no budget for this at the moment. Many thanks for your assistance.
A SC105 is an option to consider. It does +5V,-5V drive levels.