Getting Data from Serial
Posted
#1
(In Topic #926)
Enthusiast

Can someone help me please I am trying to get the Result of this command https://reference.epso….php?content_id=124#gs_lr
it makes the Epson PoS Printers send the status of the printer BUT I have no idea how to acually capture and handle the data that is being sent back to me
so for example if I send Hex 1D 72 50 it should return
does anyone know how I can capture the data coming from the Serial Printer I assume i Read it in like
but i am not sure what format the Printer would send the data in (not sure if it is string or Byte)
If someone out there who can help me with this I would be most grateful as It would allow me to add Status support to my Linux Point of sale software (My Windows version has had it for years but that is because it has been using OPoS)
Posted
Regular

From what I understand
I would write:
Code (gambas)
- Read #RS232Printer, variable_byte
It will then be the task of the subsequent instructions to know the bits states of the Byte data-type value received.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
You must first understand if the printer sends only one Byte of data or several bytes (maybe containing other values that you may not need).
From what I understand, the printer returns a message consisting of 8 bits, then of 1 Byte.
I would write:(where variable_byte is a Byte data-type variable).Code (gambas)
Read #RS232Printer, variable_byte
It will then be the task of the subsequent instructions to know the bits states of the Byte data-type value received.
When I was working on this in FeeeBASIC the program recevied the data like this 00000100 So would I still have Variable_Byte defined as byte?
Posted
Regular

Uhmmm…this could be a string of 8 ASCII numeric characters.AndyGable said
the program recevied the data like this 00000100
Have you tried to read those data as a string?……
Code (gambas)
- Read #RS232Printer, variable_string, 8
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
Uhmmm…this could be a string of 8 ASCII numeric characters.AndyGable said
the program recevied the data like this 00000100
Have you tried to read those data as a string?……Reads 8 bytes as string data- type.Code (gambas)
Read #RS232Printer, variable_string, 8
NOt yer I will try that when I get back home to the Printer
Posted
Enthusiast

Code (gambas)
- ' Gambas class file
- 'Hex 1D 72 n
- '
- 'Set up the Serial Device so it should start talking
- With RS232Printer
- .PortName = "/dev/ttyS0"
- .Speed = "9600"
- AddToListBox("Sorry Unable to connect to Printer\nPlease check settings and try again")
- AddToListBox("Ready.. Watching For incoming data from Printer")
- Sleep 0.025
- Read #RS232Printer, variable_string, 8
- AddToListBox(variable_string)
- AddToListBox("Sending Paper Status Request")
- 'Write #RS232Printer, RequestPaperStatus
- AddToListBox("Sending Cash Drawer Status Request")
- Write #RS232Printer, RequestCashDrawerStatus
- ' RS232Scanner_Read
- gw = ListBox1.Children[0]
- gw.Rows[b].Height = -1
- ListBox1.Refresh
- FMain.Refresh
- 'Wait 0.1
While the program is is running i can click the button to request the status and then I send
Code (gambas)
- Write #RS232Printer, RequestPaperStatus
to the printer but i am not sure if everything is ok with printer or it is ignoring the commands I am sending
am I sending the code corerectly is whaty I am thinking
this is what I need to send as Hex 1D 72 n = 49
this i what I am using at the moment
Chr$(&H1D) & Chr$(&H72) & Chr$(49)
Is this correct or have i messed it up some where?
Posted
Enthusiast

When I open the COver the software displays a <
when I press the Feed Key I get a \
I am not sure if this is correct or not BUT at least something is happening lol
But I was thinking I should get a 8 bits of data
Posted
Posted
Enthusiast

PJBlack said
Cool so how do I show the Bin on screen? as that is how the Printer sends the status
Code (gambas)
This is the Data I would get if I sent the following command Chr$(&H1D) & Chr$(&H72) & 50
Does any one have any idea how I can capture the above data
Posted
Regular

In general, to convert a numeric value to a binary representation of type string, you can use the native Bin() function:AndyGable said
how do I show the Bin on screen?
https://gambaswiki.org/wiki/lang/bin
You will take care to preliminarily convert the ASCII character to a numeric value using the Asc () function.
Exemplum:
____________________________________________________
IF the printer sends 8-bits data, these correspond to 1 Byte.AndyGable said
Therefore it would seem that you just need simply to read 1 Byte:
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
In general, to convert a numeric value to a binary string, you can use the native Bin() function:AndyGable said
how do I show the Bin on screen?
https://gambaswiki.org/wiki/lang/bin
You will take care to preliminarily convert the ASCII character to a numeric value using the Asc () function.
Exemplum:
____________________________________________________
IF the printer sends 8-bits data, these correspond to 1 Byte.AndyGable said
Therefore it would seem that you just need simply to read 1 byte:
Thanks for that I am now getting on screen
Code
Ready....
Watching For incoming data from Printer
10100
0
0
1111
I assume that is the printer saying all is well but it is is not in 8 bits
Posted
Regular

If you delete the Bin () function:AndyGable said
Code
Ready....
Watching For incoming data from Printer
10100
0
0
1111
I assume that is the printer saying all is well but it is is not in 8 bits
Code (gambas)
- ......
- Print variable_Byte
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
If you delete the Bin () function:AndyGable said
Code
Ready....
Watching For incoming data from Printer
10100
0
0
1111
I assume that is the printer saying all is well but it is is not in 8 bits
what numeric data do you get?Code (gambas)
...... Print variable_Byte
Code
20
0
0
15on screen I am now getting
11000110101001111
200015
because I added
While Not Eof(RS232Printer)
Read #RS232Printer, variable_Byte
DataRec &= variable_Byte
Wend
Posted
Regular

https://reference.epso…/index.php?content_id=124
it appears that each status is communicated by the printer through 1 Byte.
Infact it says: « Each status is <COLOR color="#800000">1 byte</COLOR>. »
Well, if we take the "Paper sensor status", for example we have:
«<COLOR color="#800000">Roll paper near-end sensor: paper adequate</COLOR>» = decimal value 0 (id est: &h00 in Gambas…or in C language 0x00… OK?);
and
«<COLOR color="#800000">Roll paper end sensor: paper not present</COLOR>» = decimal value 12, which corresponds to binary 00001100 (in fact in the table the third and fourth bits - index 2 and 3 - are indicated as set to 1, counting from the right).
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
From the on-line documentation, indicated by you:
https://reference.epso…/index.php?content_id=124
it appears that each status is communicated by the printer through 1 Byte.
Infact it says: « Each status is <COLOR color="#800000">1 byte</COLOR>. »
Well, if we take the "Paper sensor status", for example we have:
«<COLOR color="#800000">Roll paper near-end sensor: paper adequate</COLOR>» = decimal value 0 (id est: &h00 in Gambas…or in C language 0x00… OK?);
and
«<COLOR color="#800000">Roll paper end sensor: paper not present</COLOR>» = decimal value 12, which corresponds to binary 00001100 (in fact in the table the third and fourth bits - index 2 and 3 - are indicated as set to 1, counting from the right).
Yea That is right so how Do I get my App to show messages to say Paper Fine or Paper Low etc
<LIST>
- <LI>I want to support the following status
Paper Low
Cover Open
Cash Drawer Open
Cash Drawer Closed</LI>
Posted
Regular

Code (gambas)
Often external devices send String values (ASCII characters), but the documentation shows that your printer sends numeric values of 1 Byte data-type.
…or so at least :? I understand.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
It would seem that you have to read with the instruction "Read" every single Byte that the printer sends you.
Often external devices send String values (ASCII characters), but the documentation shows that your printer sends numeric values of 1 Byte data-type.
And how would i do that?
Posted
Regular

…then you compare the numerical value read with those present in the table of printer documentation.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

Posted
Enthusiast

Thank you so much for your input on this at the moment
I have been doing some more work and I found some old code I use to use in FreeBASIC
Code
Dim status As String
Write #Global.PrinterPort, Chr(10) & Chr(4) & 1
Global.PrinterPort.Send
While loc(Global.PortName) = 0
Sleep 1
Wend
status = Input(Loc(Global.PrinterPort), 1)
Print Bin(Val(status), 8)
If Bit(Val(status), 3) = -1 Then
Global.AddToScreenList("Kickout connector high")
Else
Global.AddToScreenList("Kickout connector low")
Endif
If Bit(Val(status), 4) = -1 Then
Global.AddToScreenList("Printer is Offline")
Else
Global.AddToScreenList("Printer is Online")
Endif
If Bit(Val(status), 6) = -1 Then
Global.AddToScreenList("Waiting for Online Recovery")
Else
Global.AddToScreenList("Not Waiting for Online Recovery")
Endif
If Bit(Val(status), 7) = -1 Then
Global.AddToScreenList("Paper fed by button")
Else
Global.AddToScreenList("Paper not fed by button")
Endif
I Tried this (hoping i would not have to do any conversion) but I get a Error message on Bit saying "Unknown Identifier"
So does anyone now the Gambas option for Bit?
Posted
Regular

I think the minimal thing we can deal with is a Byte. You can Or or And bytes with some mask (usually a Const or an Enum) to see if one or more bits are set.
e.g.
Code
Const elephant as Byte=3
...
Function IsItAnElephant(this as Byte) as Boolean
If And(this, elephant) then Return True
Return False
EndMneh. It looks right to me but I haven't actually tried it.
hth
thatbruce
Posted
Enthusiast

k9:k9.9:start [GAMBAS BOOK 3.19.5]
since you are working with serial port … this might be of intrest
k24:k24.1:k24.1.5:start [GAMBAS BOOK 3.19.5]
Posted
Regular

Of course, the Bit () function in Gambas does not exist, nor is it a function or class that you have created.AndyGable said
… I get a Error message on Bit saying "Unknown Identifier"
What should Bit () do?AndyGable said
So does anyone now the Gambas option for Bit?
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

grayghost4 said
here are all the gambas bit functions![]()
k9:k9.9:start [GAMBAS BOOK 3.19.5]
since you are working with serial port … this might be of intrest
k24:k24.1:k24.1.5:start [GAMBAS BOOK 3.19.5]
that last one does seem to help
I just can not get a reliable data from the prnter either i get 20015 (all good) or it comes like 200152001520015 so is my app not clearing the data some where?
Posted
Enthusiast

So does anyone now the Gambas option for Bit?
What should Bit () do?
see my post above
Print BTst(0, 0) …….. prints false least significant bit is 0
Print BTst(1, 0) …….. returns True least significant bit is 1
Print BTst(2, 1) ……….returns True bit two is a 1
Function Description
BClr (Number, Bit) Returns number with deleted bit' Bit'.
BSet (Number, Bit) Returns number with bit' Bit' set.
BTst (Number, Bit) Returns True if bit' Bit' is set, otherwise False.
BChg (Number, Bit) Returns Number whose bit' Bit' was inverted.
Lsl (Number, Bit) Each bit in the bit sequence of Number is shifted to the left by' Bit' bits. For the left-hand bits that are omitted, zero bits are attached to the right-hand side. The sign is ignored. (Lsl = logical shift left)
Lsr (Number, Bit) Each bit in the bit sequence of Number is shifted to the right by' Bit' bits. Zero bits are inserted on the left for the bits that are omitted on the right. (Lsr = logical shift right)
Shl (Number, Bit) Each bit in the bit sequence of Number is shifted to the left by' Bit' bits. For the left-hand bits that are omitted, zero bits are attached to the right-hand side.
Asl (Count, Bit) Synonym for Shl (count, bit). The sign is not ignored.
Shr (Number, Bit) Each bit in the bit sequence of Number is shifted to the right by' Bit' bits. The sign bit is inserted on the left for the bits that are omitted on the right.
Asr (Number, Bit) Synonym for Shr (Number, Bit)
Rol (Number, Bit) During the operation Rol, the bits rotate by the number of' bits' as if MSB (most significant bit - highest value bit position) and LSB (less significant bit - lowest value bit position) were connected to each other. The bit that is shifted out of the bit sequence to the left has the same value as the bit that is shifted in from the right. (Rol = Rotate left)
Ror (Number, Bit) During operation Ror(), the bits rotate by the number of 'bits' as if MSB and LSB were connected to each other. The bit that is shifted out of the bit sequence to the right has the same value as the bit that is shifted in from the left.
1 guest and 0 members have just viewed this.



