Page 1 of 3
Getting Data from Serial
Posted: Tuesday 8th November 2022 10:11pm
by AndyGable
Hi Everyone,
Can someone help me please I am trying to get the Result of this command
https://reference.epson-biz.com/modules ... =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
Drawer kick-out connector status (n = 2, 50)
Bit Binary Hex Decimal Status
0 0 00 0 Drawer kick-out connector pin 3 is LOW.
1 01 1 Drawer kick-out connector pin 3 is HIGH.
1 – 3 − − − (Reserved)
4 0 00 0 Fixed
5, 6 − − − (Reserved)
7 0 00 0 Fixed
does anyone know how I can capture the data coming from the Serial Printer I assume i Read it in like
Try Read #RS232Printer, Global.ScannerData, Lof(RS232Printer)
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)
Re: Getting Data from Serial
Posted: Tuesday 8th November 2022 10:53pm
by vuott
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:
Read #RS232Printer, variable_byte
(where
variable_byte is a
Byte data-type variable).
It will then be the task of the subsequent instructions
to know the bits states of the Byte data-type value received.
Re: Getting Data from Serial
Posted: Wednesday 9th November 2022 9:18am
by AndyGable
vuott wrote: ↑Tuesday 8th November 2022 10:53pm
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:
Read #RS232Printer, variable_byte
(where
variable_byte is a
Byte data-type variable).
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?
Re: Getting Data from Serial
Posted: Wednesday 9th November 2022 10:59am
by vuott
AndyGable wrote: ↑Wednesday 9th November 2022 9:18am
the program recevied the data like this 00000100
Uhmmm...this could be a string of 8 ASCII numeric characters.
Have you tried to read those data as a string?......
Read #RS232Printer, variable_string, 8
Reads 8 bytes as string data- type.
Re: Getting Data from Serial
Posted: Wednesday 9th November 2022 2:41pm
by AndyGable
vuott wrote: ↑Wednesday 9th November 2022 10:59am
AndyGable wrote: ↑Wednesday 9th November 2022 9:18am
the program recevied the data like this 00000100
Uhmmm...this could be a string of 8 ASCII numeric characters.
Have you tried to read those data as a string?......
Read #RS232Printer, variable_string, 8
Reads 8 bytes as string data- type.
NOt yer I will try that when I get back home to the Printer
Re: Getting Data from Serial
Posted: Wednesday 9th November 2022 5:15pm
by AndyGable
ok so I have this so far
' Gambas class file
Public RS232Printer As SerialPort
'Hex 1D 72 n
Public RequestPaperStatus As String =Chr$(&H1D) & Chr$(&H72) & Chr$(49) ' Paper Status
Public RequestCashDrawerStatus As String = "u001D" & "r" & Chr(50) ' 50 for the Cash Drawer
Public Sub Form_Open()
'
RS232Printer = New SerialPort As "RS232Printer"
'Set up the Serial Device so it should start talking
With RS232Printer
.PortName = "/dev/ttyS0"
.Speed = "9600"
.Parity = SerialPort.None
.DataBits = SerialPort.bits8
.StopBits = SerialPort.bits1
.FlowControl = SerialPort.None
End With
Try RS232Printer.Open
If Error Then
AddToListBox("Sorry Unable to connect to Printer\nPlease check settings and try again")
Else
If RS232Printer.Status = Net.Active Then
RS232Printer.Watch(gb.Write, 1)
AddToListBox("Ready.. Watching For incoming data from Printer")
Endif
End If
End
Public Sub RS232Printer_Read()
Dim variable_string As String = Null
Sleep 0.025
Read #RS232Printer, variable_string, 8
AddToListBox(variable_string)
If Error Then
AddToListBox("Error With Incoming Serial Data\n" & Error.Text)
Endif
End
Public Sub Button1_Click()
AddToListBox("Sending Paper Status Request")
'Write #RS232Printer, RequestPaperStatus
AddToListBox("Sending Cash Drawer Status Request")
Write #RS232Printer, RequestCashDrawerStatus
' RS232Scanner_Read
End
Public Sub AddToListBox(textToShow As String)
Dim gw As GridView
Dim b As Byte
ListBox1.Add(Trim(textToShow))
ListBox1.Index = ListBox1.Count - 1
gw = ListBox1.Children[0]
b = ListBox1.List.Max
gw.Rows.Height = -1
ListBox1.Refresh
FMain.Refresh
'Wait 0.1
End
While the program is is running i can click the button to request the status and then I send
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?
Re: Getting Data from Serial
Posted: Thursday 10th November 2022 9:13am
by AndyGable
After some work I have the Printer SORT of talking to my software
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
Re: Getting Data from Serial
Posted: Thursday 10th November 2022 12:43pm
by PJBlack
Ascii Hex Dec Bin
< 3C 60 00111100
\ 5C 92 01011100
Re: Getting Data from Serial
Posted: Thursday 10th November 2022 1:40pm
by AndyGable
PJBlack wrote: ↑Thursday 10th November 2022 12:43pm
Ascii Hex Dec Bin
< 3C 60 00111100
\ 5C 92 01011100
Cool so how do I show the Bin on screen? as that is how the Printer sends the status
Bit Binary Hex Decimal Status
0, 1 00 00 0 Roll paper near-end sensor: paper adequate.
11 03 3 Roll paper near-end sensor: paper not present.
2, 3 00 00 0 Roll paper end sensor: paper present.
11 0C 12 Roll paper end sensor: paper not present.
4 0 00 0 Fixed
5,6 − − − (Reserved)
7 0 00 0 Fixed
This is the Data I would get if I sent the following command
Chr$(&H1D) & Chr$(&H72) & 50
Bit Binary Hex Decimal Status
0 0 00 0 Drawer kick-out connector pin 3 is LOW.
1 01 1 Drawer kick-out connector pin 3 is HIGH.
1 – 3 − − − (Reserved)
4 0 00 0 Fixed
5, 6 − − − (Reserved)
7 0 00 0 Fixed
Does any one have any idea how I can capture the above data
Re: Getting Data from Serial
Posted: Thursday 10th November 2022 2:15pm
by vuott
AndyGable wrote: ↑Thursday 10th November 2022 1:40pm
how do I show the Bin on screen?
In general, to convert a numeric value to a binary representation of type
string, you can use the native Bin() function:
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:
Print Bin (Asc ("<"))
____________________________________________________
AndyGable wrote: ↑Thursday 10th November 2022 1:40pm
Bit Binary Hex Decimal Status
0 0 00 0 Drawer kick-out connector pin 3 is LOW.
1 01 1 Drawer kick-out connector pin 3 is HIGH.
1 – 3 − − − (Reserved)
4 0 00 0 Fixed
5, 6 − − − (Reserved)
7 0 00 0 Fixed
Does any one have any idea how I can capture the above data
IF the printer sends
8-bits data, these correspond to 1 Byte.
Therefore it would seem that you just need simply to read 1 Byte:
Dim variable_Byte As Byte
Read #RS232Printer, variable_Byte
Print Bin(variable_Byte)