RS232 / Serial Scale Help

Post your Gambas programming questions here.
User avatar
thatbruce
Posts: 159
Joined: Saturday 4th September 2021 11:29pm

Re: RS232 / Serial Scale Help

Post by thatbruce »

@BruceS, Yes I was going to suggest the same but I still haven't got an answer from AndyGable to my question
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?
@AndyGable,
I have done a print to the debug console and it is empty
is the answer to a different question. Printing something and inspecting something are not the same.
Have you ever noticed that software is never advertised using the adjective "spreadable".
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: RS232 / Serial Scale Help

Post by AndyGable »

thatbruce wrote: Thursday 9th September 2021 9:35pm @BruceS, Yes I was going to suggest the same but I still haven't got an answer from AndyGable to my question
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?
@AndyGable,
I have done a print to the debug console and it is empty
is the answer to a different question. Printing something and inspecting something are not the same.
Hi @thatbruce

the Global.ScaleData is empty nothing is being placed into it
User avatar
thatbruce
Posts: 159
Joined: Saturday 4th September 2021 11:29pm

Re: RS232 / Serial Scale Help

Post by thatbruce »

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
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
thatbruce
Posts: 159
Joined: Saturday 4th September 2021 11:29pm

Re: RS232 / Serial Scale Help

Post by thatbruce »

Just to summarise where we are at the moment regarding Gambas.
  • Your program is using a Write command to send a request to the scale.
  • Your program waits a little while
  • It then attempts to get the scale's response using a Try Read construct
Now this read succeeds because it almost always will*. 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.
  • Your program then tests to see if the Read actually found some data.
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.
Have you ever noticed that software is never advertised using the adjective "spreadable".
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: RS232 / Serial Scale Help

Post by AndyGable »

thatbruce wrote: Friday 10th September 2021 10:51am 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
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: RS232 / Serial Scale Help

Post by AndyGable »

This is the full file that was sent by Datalogic

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.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: RS232 / Serial Scale Help

Post by BruceSteers »

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"

:)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 159
Joined: Saturday 4th September 2021 11:29pm

Re: RS232 / Serial Scale Help

Post by thatbruce »

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"
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).

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 programmable[/b]. 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
b) makes their
So to send STX do an alt function 002,S11,Enter,Alt Function 003
line bullshit. (But it might be a half-garbled bit of "Hyperterminal" text and so is absolutely useless here.)
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 :( - more later/tomorrow.

b
Have you ever noticed that software is never advertised using the adjective "spreadable".
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: RS232 / Serial Scale Help

Post by AndyGable »

@ThatBruce

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

1) I am using a DB9
2) 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 :( I am sorry for this your brain is hurting mine is about to melt
User avatar
thatbruce
Posts: 159
Joined: Saturday 4th September 2021 11:29pm

Re: RS232 / Serial Scale Help

Post by thatbruce »

Morning Andy,

Another side-ways question: Is there a device access controller (DAC or sometimes EAC, LAC or DCU or even FIIK 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 they are using flow control terms to describe it. :evil: :evil: :evil: Right, the conversation is fundamentally:

Code: Select all

Computer sends "Weight Request" -> Operator puts item on scale ->  Scale measures weight -> Scale sends "Weight Format"

Alternatively and not specified is what happens if the item is not put on the scale or ... or ... or ... (We may have an "or" here.)

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: Select all

["Hey POS"]["Connect me to the scales"]["Hey scales, do a '1' function"]["That is all" and stops talking]
which they have specified as :

Code: Select all

[ STX ][ Address ][ FC ][ ETX ] or
[ S ][ 1 ][ 1 ][  C/R  ]
Now, we can do all that without resorting to hex at all. Just Write #RS232Scanner, "S11\n" should do it.

(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: Select all

[ STX ][ Address ][ FC ][ xxxxx ][ ETX ] or
[ S ][ 1 ][ 1 ][ <the weight I guess> ][ C/R ]
and as you implied originally, that should be just a string of ascii characters. So, if
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: Select all

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

End
What happens?

b
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply