[Solved] Sending Data to the Serial Port
Posted
#1
(In Topic #581)
Enthusiast

I was hoping someone could advice me how I can send text to the Serial port with Gambas 3.
I have according to my code the port open but I can not work out how to send data to the device (it is a small LCD screen)
I want to first get it to show "Hello World"
any advice would be most welcomed
Posted
Regular

If you haven't already done so, I'd suggest doing a test first to establish that all is OK with your hardware.
Are you connecting an RS232 port from a computer to your mini-LCD display?
You will need protocol information for your display (e.g. how to set baud rates, flow control & so on).
Posted
Regular

Code (gambas)
- With SerialPort1
- .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer
- .Speed = 1200 'must match printer
- .Send = "Hello World!"
…I wish I could rig up a serial comms test-bed and play along with you!
Posted
Trainee
As mentioned above, first try it with a standard serial communication software to see if the hardware works. Personally, I prefer either Moserial or Cutecom for simple communication.
Posted
Enthusiast

stevedee said
…once you have proved that your computer can communicate with your display using a program like minicom, you could try a bit of Gambas like this:-Code (gambas)
With SerialPort1 .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer .Speed = 1200 'must match printer .Send = "Hello World!"
…I wish I could rig up a serial comms test-bed and play along with you!
I have tried your example and I get the following error on .send
Code
'SerialPort.Send is not a property in FMain:14Any idea what this means?
Posted
Regular

Also you may need to use the Begin method, so try:-
Code (gambas)
- With SerialPort1
- .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer
- .Speed = 1200 'must match printer
- .Begin()
- .Send("Hello World!")
Posted
Enthusiast

stevedee said
Sorry Andy, I'm an idiot. Send is a method.
Also you may need to use the Begin method, so try:-Code (gambas)
With SerialPort1 .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer .Speed = 1200 'must match printer .Begin() .Send("Hello World!")
Hey Thanks for the advice Stevedee but now I am getting "Too many arguments in FMain:15 on the .Send("Hello World!") line any advice?
Posted
Regular

Looking more closely, the Send method does not take any arguments, so should be replaced by .Send()
I was hoping that there was an easy way to send some text, but the documentation says you need to establish a Stream and then use Stream methods to send & receive data.
I'll try to look at this again when I have more time.
Posted
Trainee
Here is how I set it up:
Private Comm1 As SerialPort
' Com port initialization
Comm1.PortName = cbCom1.Text
Comm1.Speed = 115200
Comm1.Parity = Comm1.None
Comm1.DataBits = 8
Comm1.StopBits = 1
Comm1.FlowControl = Comm1.None
' Start by using a serial port buffer
Comm1.Begin
' Now write many bytes to that port in a for-loop or whatever way, using the command:
Write #Comm1, data As Byte
' Finally, the buffered data can be send using:
Comm1.Send
Posted
Enthusiast

progger said
I am doing a lot of serial communications using Gambas.
Here is how I set it up:
Private Comm1 As SerialPort
' Com port initialization
Comm1.PortName = cbCom1.Text
Comm1.Speed = 115200
Comm1.Parity = Comm1.None
Comm1.DataBits = 8
Comm1.StopBits = 1
Comm1.FlowControl = Comm1.None
' Start by using a serial port buffer
Comm1.Begin
' Now write many bytes to that port in a for-loop or whatever way, using the command:
Write #Comm1, data As Byte
' Finally, the buffered data can be send using:
Comm1.Send
so how do I send the text "Hello World"?
Posted
Trainee
Posted
Enthusiast

Thank-you I have it working now
the next Serial challange I will have is getting the status data from the PoS Printer (but that can wait for another day)
1 guest and 0 members have just viewed this.



