Getting Data from Serial

Post your Gambas programming questions here.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

vuott wrote: Thursday 10th November 2022 2:15pm
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 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)

Thanks for that I am now getting on screen

Code: Select all

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
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting Data from Serial

Post by vuott »

AndyGable wrote: Thursday 10th November 2022 2:46pm

Code: Select all

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
If you delete the Bin () function:
......
Print variable_Byte
what numeric data do you get?
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

vuott wrote: Thursday 10th November 2022 2:52pm
AndyGable wrote: Thursday 10th November 2022 2:46pm

Code: Select all

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
If you delete the Bin () function:
......
Print variable_Byte
what numeric data do you get?

Code: Select all

20
0
0
15
on screen I am now getting
11000110101001111
200015

because I added

While Not Eof(RS232Printer)
Read #RS232Printer, variable_Byte
DataRec &= variable_Byte
Wend
Last edited by AndyGable on Thursday 10th November 2022 3:38pm, edited 1 time in total.
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting Data from Serial

Post by vuott »

From the on-line documentation, indicated by you:
https://reference.epson-biz.com/modules ... ent_id=124
it appears that each status is communicated by the printer through 1 Byte.
Infact it says: « Each status is 1 byte. »

Well, if we take the "Paper sensor status", for example we have:
«Roll paper near-end sensor: paper adequate» = decimal value 0 (id est: &h00 in Gambas...or in C language 0x00... OK?);
and
«Roll paper end sensor: paper not present» = 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 !

Amare memorentes atque deflentes ad mortem silenter labimur.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

vuott wrote: Thursday 10th November 2022 3:15pm From the on-line documentation, indicated by you:
https://reference.epson-biz.com/modules ... ent_id=124
it appears that each status is communicated by the printer through 1 Byte.
Infact it says: « Each status is 1 byte. »

Well, if we take the "Paper sensor status", for example we have:
«Roll paper near-end sensor: paper adequate» = decimal value 0 (id est: &h00 in Gambas...or in C language 0x00... OK?);
and
«Roll paper end sensor: paper not present» = 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

  • I want to support the following status
    Paper Low
    Cover Open
    Cash Drawer Open
    Cash Drawer Closed
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting Data from Serial

Post by vuott »

It would seem that you have to read with the instruction "Read" every single Byte that the printer sends you.
Read #printer-file-device, variable_BYTE_data-type
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.
Last edited by vuott on Thursday 10th November 2022 3:41pm, edited 1 time in total.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

vuott wrote: Thursday 10th November 2022 3:33pm 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?
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting Data from Serial

Post by vuott »

In general, in Gambas to read the value of 1 Byte data-type from a stream (file), you do what I have already indicated, and which I repeat here as a simple practical example:
Dim variable_byte As Byte

Read #variable_file, variable_byte
...then you compare the numerical value read with those present in the table of printer documentation.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
grayghost4
Posts: 187
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Getting Data from Serial

Post by grayghost4 »

Select case variable_byte 

  Case 20 
    textbox.text = "draw  Open"   'or what ever it indicates 

  Case 15
    textbox2.text = "paper out"

End Select



AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

Hi Everyone

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

    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?
Post Reply