Buongiorno,
devo lavorare con un dispositivo tramite RS232, che mi risponde in ASCII e devo inviare i comandi in Esadecimale
"
Receive and Transmit Use an interrupt driven comm event on the appropriate com port. Settings are 9600-8-1-None.
Must be noted again Any data sent from PC to BOX-RS232 box, that should use HEX data Any data that PC received from BOX-RS232 box, that is ASCII data So when user test command with BOX Demo tool or RS232 tools,must select the “hex” mode to send data
"
Pensavo di risolvere con Jserial e ho preso come base un progetto di esempio di chat pubblicato da Erel .
Problema: riesco a comunicare ma perdo dei valori sulla risposta che mi invia in Ascii.
Il costruttore del dispositivo, fornisce anche un eseguibile che , oltre alle classiche impostazioni ( 9600-8-1-None ) , vedo anche dei valori di impostazione buffer
Domanda : sapete se esiste un modo per impostare anche il buffer affinché nell'evento AStream_NewData (Buffer() As Byte), non perdo valori ?
Grazie in anticipo
vedi sotto codice
devo lavorare con un dispositivo tramite RS232, che mi risponde in ASCII e devo inviare i comandi in Esadecimale
"
Receive and Transmit Use an interrupt driven comm event on the appropriate com port. Settings are 9600-8-1-None.
Must be noted again Any data sent from PC to BOX-RS232 box, that should use HEX data Any data that PC received from BOX-RS232 box, that is ASCII data So when user test command with BOX Demo tool or RS232 tools,must select the “hex” mode to send data
"
Pensavo di risolvere con Jserial e ho preso come base un progetto di esempio di chat pubblicato da Erel .
Problema: riesco a comunicare ma perdo dei valori sulla risposta che mi invia in Ascii.
Il costruttore del dispositivo, fornisce anche un eseguibile che , oltre alle classiche impostazioni ( 9600-8-1-None ) , vedo anche dei valori di impostazione buffer
Domanda : sapete se esiste un modo per impostare anche il buffer affinché nell'evento AStream_NewData (Buffer() As Byte), non perdo valori ?
Grazie in anticipo
vedi sotto codice
Base esempio Erel-chat:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim btnOpen As Button
Dim cmbPort As ComboBox
Dim txtInput As TextField
Dim txtLog As TextArea
Dim lblStatus As Label
Private sp As Serial
Private astream As AsyncStreams
Private BaudRate =9600 As Int
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
MainForm.Title = "MDB Comunication"
MainForm.BackColor = fx.Colors.White
sp.Initialize("")
cmbPort.Items.AddAll(sp.ListPorts)
End Sub
Sub btnOpen_Action
sp.Initialize(Null)
sp.Open(cmbPort.Value)
sp.SetParams(9600,8,1,0)
astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")
txtInput.Enabled = True
btnOpen.Enabled = False
lblStatus.Text = "Status: Open"
End Sub
Sub MainForm_Closed
sp.Close
End Sub
Sub AStream_NewData (Buffer() As Byte)
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
LogMessage("NewData :", s)
'Log (s)
End Sub
Sub txtInput_Action
Dim conv As ByteConverter
Dim data() As Byte = conv.StringToBytes(txtInput.Text, "UTF8")
astream.Write(data)
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub