I've got no response from serial port
Hi,i found sample source code from this forum to make communication to modem. I tried that code to make communication to cellular phone which is connected to serial port by data cable. There is no response at all from the phone. I'm confused, what's wrong with the code? But if i use hyper terminal on windows 2000 to send AT commands,the phone gives responds. FYI,i use Siemens C35i cellular phone. Is there someone who can tell me what's wrong with the code ?
Thank's very much
Here is the code :
import java.io.*;
import java.util.*;
import javax.comm.*;
public class Coba11 implements SerialPortEventListener {
static CommPortIdentifier portId;
Enumeration portList;
DataInputStream inputStream;
DataOutputStream outputStream;
SerialPort serialPort;
public static void main(String[] args) {
boolean portFound = false;
String defaultPort = "COM1";
Coba11 cb = new Coba11();
cb.portList = CommPortIdentifier.getPortIdentifiers();
while (cb.portList.hasMoreElements()) {
System.out.println("Masuk ke dalam while");
cb.portId = (CommPortIdentifier) cb.portList.nextElement();
if (cb.portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (cb.portId.getName().equals("COM1")) {
System.out.println("Found port: "+defaultPort);
portFound = true;
try {
cb.serialPort = (SerialPort) cb.portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
//get inputstream and outputstream from the port
try {
cb.inputStream = new DataInputStream(cb.serialPort.getInputStream());
cb.outputStream = new DataOutputStream(cb.serialPort.getOutputStream());
} catch (IOException e) {}
try {
cb.serialPort.addEventListener(cb);
} catch (TooManyListenersException e) {}
cb.serialPort.notifyOnCTS(true);
cb.serialPort.notifyOnDSR(true);
cb.serialPort.notifyOnRingIndicator(true);
cb.serialPort.notifyOnCarrierDetect(true);
cb.serialPort.notifyOnOverrunError(true);
cb.serialPort.notifyOnParityError(true);
cb.serialPort.notifyOnFramingError(true);
cb.serialPort.notifyOnBreakInterrupt(true);
cb.serialPort.notifyOnDataAvailable(true);
try {
cb.serialPort.setSerialPortParams(19200, SerialPort.DATABITS_7,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
//send commands to the cellular phone
String atCommand = "ATD08128533615";
try {
cb.outputStream.write(atCommand.getBytes());
atCommand = "AT";
Thread.sleep(1000);
cb.outputStream.write(atCommand.getBytes());
} catch (IOException e) {}
catch (InterruptedException e) {}
try {
Thread.sleep(40000);
atCommand = "AT";
cb.outputStream.write(atCommand.getBytes());
Thread.sleep(500);
} catch (InterruptedException e) {}
catch (IOException e) {}
try {
cb.inputStream.close();
cb.outputStream.close();
} catch (IOException e) {}
cb.serialPort.close();
System.out.println("Serial Port is closed");
if (!portFound) {
System.out.println("port " + defaultPort + " not found.");
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
int numBytes = inputStream.read(readBuffer);
String string = new String(readBuffer);
System.out.print(string);
} catch (IOException e) {}
break;
the very first command you have to send to the modem is AT
wait 2 seconds then start sendind other commands
Similar Messages
-
Reading a char array from Serial port
Need help!
Hi, I've got the following problem - I wanna read a input stream from serial port and I use at the moment the following method (reading bytewise):
public String receiveText (){
byte ch;
fStrBuf.delete(0,fStrBuf.length()); //clearing the buffer
try{
do {
ch = (byte) fPortInStream.read();
fStrBuf.append( (char) ch);
while ( (byte) ch != 0x03); //The end of frame byte
}catch(IOException ioe) {};
return fStrBuf.toString();It works pretty well, but disadvantage is that it's too slow to use it in the thread (at least I think so)
How can I change it to read all available data from the port (or simply faste). I don't need event listeners, because it's a request-responde communication.
I tried smth. like this
byte[] readBuffer = new byte[20];
try {
while (fPortInStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
fStrBuf.append(readBuffer);
} catch (IOException e) {}
return fStrBuf.toString();But it doesn't seem to work :-(May I suggest that you use StringBuilder rather than StringBuffer. It has less overhead because it is not threadsafe. I do synchronous serial port stuff with Opto 22, and i have no listeners enabled.
Appending to the String(Builder/Buffer) directly from the byte buffer mangles it. So I use a string (ugh). With the Opto22 brain boards, i am looking for a carriage return as a term char. It either finds it or times out.
This is the best i have come up with so far:
StringBuilder response = new StringBuilder();
String data = new String();
long msTimeOut = 2000;
public void getResponse () throws IOException {
byte[] readBuff = {0};
int charAvail;
response.delete(0,response.length());
long ts = Calendar.getInstance().getTimeInMillis();
try {
while ( readBuff[readBuff.length-1] != '\r' ) {
charAvail = inputStream.available();
if ( charAvail > 0 ) {
readBuff = new byte[charAvail];
inputStream.read(readBuff);
response.append(new String(readBuff));
if ( Calendar.getInstance().getTimeInMillis() > (ts + msTimeOut) ) {
response.delete(0,response.length());
response.append("TIMEOUT");
break;
} catch (IOException e) { e.printStackTrace(); throw e; }
data = response.substring(0);
} I just starting writing Java about 4 days ago, so caveat emptor. -
How to get data from serial port to GUI textArea
From Serial Port.....
Messages from base (always 5 bytes):
0xAA, 0, 0, 0, 0xBB - IDLE Mode
0xAA, 0, 0x80, 0x80, 0xBB - Question Mode
messages from terminal (always 6 bytes):
0xAA, a, b, c, chksum, 0xBB
where chksum = a+b+c;
a = address (0-250)
the 2 MSB's of b represenet the answer:
0 0 - A
0 1 - B
1 0 - C
1 1 - D
the 6LSB's of b and 8bits of c is the time for answer, in milliseconds.
(0-16384 milliseconds)
I have VB Code for that but I want the same thing in Java ...
Can any one help me?
Here's VB Code..
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Aakar GUI"
ClientHeight = 4665
ClientLeft = 60
ClientTop = 375
ClientWidth = 6105
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 311
ScaleMode = 3 'Pixel
ScaleWidth = 407
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdPort
Caption = "Open Port"
Height = 375
Left = 120
TabIndex = 4
Top = 600
Width = 1455
End
Begin VB.ComboBox cmbPort
Height = 315
ItemData = "Form1.frx":0000
Left = 120
List = "Form1.frx":0016
Style = 2 'Dropdown List
TabIndex = 3
Top = 120
Width = 2895
End
Begin VB.CommandButton cmdEnd
Caption = "End"
Height = 495
Left = 1560
TabIndex = 2
Top = 1320
Width = 1215
End
Begin VB.CommandButton cmdStart
Caption = "Start"
Height = 495
Left = 120
TabIndex = 1
Top = 1320
Width = 1215
End
Begin VB.TextBox txtMessage
Height = 2040
Left = 119
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 2475
Width = 5848
End
Begin VB.Timer tmrRead
Enabled = 0 'False
Interval = 1
Left = 2040
Top = 600
End
Begin MSCommLib.MSComm MSComm1
Left = 3120
Top = 360
_ExtentX = 1164
_ExtentY = 1164
_Version = 393216
DTREnable = 0 'False
ParityReplace = 45
SThreshold = 1
End
Begin VB.Label Label5
Caption = "Result Data:"
Height = 375
Left = 120
TabIndex = 5
Top = 2115
Width = 1320
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim PortIsOpen As Boolean
Dim Answers(4) As String
Dim RejectKeystroke As Boolean
Private Sub cmbPort_Change()
Debug.Print cmbPort.ListIndex
End Sub
Private Sub cmbPort_Validate(Cancel As Boolean)
'Cancel = True
End Sub
Private Sub cmdEnd_Click()
MSComm1.Output = "e"
txtMessage.Text = ""
End Sub
Private Sub cmdPort_Click()
On Error GoTo ErrorHandler
If cmbPort.ListIndex < 0 Then Exit Sub
If PortIsOpen Then
cmbPort.Enabled = True
MSComm1.PortOpen = False
PortIsOpen = False
cmdPort.Caption = "Open Port"
cmdStart.Enabled = False
cmdEnd.Enabled = False
Else
MSComm1.CommPort = cmbPort.ListIndex + 1
cmbPort.Enabled = False
MSComm1.PortOpen = True
PortIsOpen = True
cmdPort.Caption = "Close Port"
cmdStart.Enabled = True
cmdEnd.Enabled = True
End If
Exit Sub
ErrorHandler:
Debug.Print Err.Number
Debug.Print Err.Description
MsgBox Err.Description, vbExclamation Or vbOKOnly, "Error opening port"
cmbPort.Enabled = True
PortIsOpen = False
cmdPort.Caption = "Open Port"
cmdStart.Enabled = False
cmdEnd.Enabled = False
End Sub
Private Sub cmdStart_Click()
MSComm1.Output = "s"
txtMessage.Text = ""
End Sub
Private Sub Form_Initialize()
Dim tmp As Variant
tmp = InitCommonControls
End Sub
Private Sub Form_Load()
Answers(0) = "A"
Answers(1) = "B"
Answers(2) = "C"
Answers(3) = "D"
'MSComm1.Settings = "9600,n,8,1"
''MSComm1.Settings = "115200,n,8,1"
'MSComm1.PortOpen = True
On Error GoTo ErrorHandler1
MSComm1.CommPort = 1 ' comm port 1
MSComm1.RThreshold = 1 ' use 'on comm' event processing
MSComm1.Settings = "9600,n,8,1" ' baud, parity, data bits, stop bits
MSComm1.SThreshold = 1 ' allows us to track Tx LED
MSComm1.InputMode = comInputModeText 'comInputModeBinary ' binary mode, you can also use
' comInputModeText for text only use
PortIsOpen = False
cmbPort.ListIndex = 0
' open the port
MSComm1.PortOpen = True
cmbPort.Enabled = False
PortIsOpen = True
cmdPort.Caption = "Close Port"
cmdStart.Enabled = True
cmdEnd.Enabled = True
Exit Sub
ErrorHandler1:
Debug.Print Err.Description
PortIsOpen = False
cmbPort.Enabled = True
cmdPort.Caption = "Open Port"
cmdStart.Enabled = False
cmdEnd.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MSComm1.PortOpen Then MSComm1.PortOpen = False
End Sub
Private Sub lblOption_Click()
End Sub
Private Sub MSComm1_OnComm()
' Synopsis: Handle incoming characters, 'On Comm' Event
' Description: By setting MSComm1.RThreshold = 1, this event will fire for
' each character that arrives in the comm controls input buffer.
' Set MSComm1.RThreshold = 0 if you want to poll the control
' yourself, either via a TImer or within program execution loop.
' In most cases, OnComm Event processing shown here is the prefered
' method of processing incoming characters.
Dim i As Long
Dim sBuff As String ' buffer for holding incoming characters
Const MTC As String = vbCrLf ' message terminator characters (ususally vbCrLf)
Const LenMTC As Long = 2 ' number of terminator characters, must match MTC
Dim iPtr As Long ' pointer to terminatior character
' OnComm fires for multiple Events
' so get the Event ID & process
Select Case MSComm1.CommEvent
' Received RThreshold # of chars, in our case 1.
Case comEvReceive
' read all of the characters from the input buffer
' StrConv() is required when using MSComm in binary mode,
' if you set MSComm1.InputMode = comInputModeText, it's not required
'sBuff = sBuff & StrConv(MSComm1.Input, vbUnicode)
'If Len(txtMessage.Text) > 4096 Then txtMessage.Text = ""
sBuff = MSComm1.Input
Dim ch As String
Dim PacketStart As Boolean
Dim PacketLength As Integer
Dim Packet() As String
PacketStart = False
PacketLength = 0
While (Len(sBuff) > 0)
ch = Left(sBuff, 1)
If (ch = Chr(&HAA)) Then PacketStart = True
If (ch = Chr(&HBB)) Then PacketStart = False
If (ch <> Chr(&HAA) And ch <> Chr(&HBB)) Then
PacketLength = PacketLength + 1
ReDim Preserve Packet(PacketLength)
Packet(PacketLength) = ch
End If
'txtMessage.Text = txtMessage.Text + Format(Hex(Asc(ch)), " @@")
sBuff = Right(sBuff, Len(sBuff) - 1)
Wend
If (PacketLength = 3) Then
Debug.Print "Command packet recieved"
'txtMessage.Text = txtMessage.Text + vbCrLf + "Address =" + Str(Asc(Packet(1)))
'txtMessage.Text = txtMessage.Text + vbCrLf + "Address =" + Str(Asc(Packet(2)))
End If
If (PacketLength = 4) Then
Debug.Print "Response packet recieved"
txtMessage.Text = txtMessage.Text + "Address =" + Str(Asc(Packet(1))) + _
" Answer = " + Answers((Asc(Packet(2)) And &HC0) / 64) + _
" Time =" + Str((Asc(Packet(2)) And &H3F) * 256 + (Asc(Packet(3)))) + "mS" + vbCrLf
'txtMessage.Text = txtMessage.Text + vbCrLf + "Address =" + Str(Asc(Packet(1)))
'txtMessage.Text = txtMessage.Text + vbCrLf + "Option =" + Str((Asc(Packet(2)) And &HC0) / 64)
'txtMessage.Text = txtMessage.Text + vbCrLf + "Time =" + Str((Asc(Packet(2)) And &H3F) * 256 + (Asc(Packet(3))))
End If
If (PacketLength <> 4 And PacketLength <> 3) Then Debug.Print "Unknown packet of length" + Str(PacketLength) + " recieved"
txtMessage.Text = txtMessage.Text + vbCrLf
' An EOF charater was found in the input stream
Case comEvEOF
DoEvents
' There are SThreshold number of characters in the transmit buffer.
Case comEvSend
DoEvents
' A Break was received.
Case comEventBreak
DoEvents
' Framing Error
Case comEventFrame
DoEvents
' Data Lost.
Case comEventOverrun
DoEvents
' Receive buffer overflow.
Case comEventRxOver
DoEvents
' Parity Error.
Case comEventRxParity
DoEvents
' Transmit buffer full.
Case comEventTxFull
' Unexpected error retrieving DCB]
Case comEventDCB
DoEvents
End Select
End Sub
Private Sub tmrRead_Timer()
'MSComm1.Output = vbCrLf + vbCrLf
'MSComm1.Output = Chr(128)
End Sub
Private Sub txtMessage_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 Or Shift = 4 Then RejectKeystroke = False Else RejectKeystroke = True
End Sub
Private Sub txtMessage_KeyPress(KeyAscii As Integer)
If RejectKeystroke Then
KeyAscii = 0
End If
End SubThanks in advance..I want to replicate the entire VB program as Java Program.
This has to be included in my project which i am doing in java. -
Problem while reading data from Serial Port
Hi All,
I am facing some problem while reading data from Serial Port.
As per the requirement I am writing the data on Serial Port and waiting for response of that data.
Notification for data availabilty is checked with method public void serialEvent(SerialPortEvent event) of javax.comm.SerialPortEventListener.
When we are writing data on the port one thread i.e. "main" thread is generated and when data availability event occures another thread "Win32SerialPort Notification thread" is generated. This creates problem for me as we can't control thread processing.
So can anybody pls explain me how to overcome this problem?
Regards,
NehaMy Problem is:-
I am simoultaneouly wrting data on port & reading data from port.
First I write data on port using outputStream.write() method. Now when target side sends me response back for the request on serial port DATA_AVAILABLE of SerialPortEventListner event occured,we are reading data from serial port.Now till the time we didn't get the response from target next command can't be written on the serial port. When we are writing data on port main thread is executed.Now my problem starts when DATA_AVAILABLE event occured.At this point another thread is created.Due to this my program writes data of next command without reading response of previous command.To solve this prob. I have used wait() & notify() methods as follows.But again due to this my pc hangs after execution of 2 commands. (PC hang in while loop in a code provided below.)
From SOPs I could figure it out that after 2 commands we are not able to write data on serial port so DATA_AVAILABLE event doesn't occure n pro. goes in wait state.
Can anybody help me to solve this issue.
Neha.
Code:
public void serialEvent(SerialPortEvent event)
switch (event.getEventType())
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
try
dataThread = Thread.currentThread();
dataThread.setPriority(10);
dataAvailable = true;
byte[] tempArray=new byte[availableBytes];
inputStream.read(tempArray);
catch (IOException io)
SOP(io, "Error in serialEvent callback call for event DATA_AVAILABLE");
public void writetoPort(byte[] data) throws IOException
outputStream.write(data);
while(finalTimeOut >= actualTime)
if( ! dataAvailable)
actualTime = System.currentTimeMillis();
else
synchronized (mainThread)
mainThread = Thread.currentThread();
mainThread.wait();
public void sendDatatoUser(byte[] b) throws Exception, HWCCSystemFailure
obj.returnData(b);
synchronized(mainThread)
mainThread.notify();
-
Unable to capture data from Serial port using LVRT2010 in single core pentium 4 machine
I am using application written in Labview using windows Labview
Runtime environment 2010. Application creates a tunnel to intercept data from
Serial port.
My problem is, Currently, I am using single core Pentium
processor. When I am trying to intercept the data between COM1 and COM7 (COM 7
is a virtual port) it is not able to capture data.
When I am running Labview RT environment using dual core
processor machine it is running normally. I wonder whether it could be the compatibility issues with
single core Pentium processor.Hi Magnetica
Are both of the machines running the same runtime engine,
drivers ect?
Have you had RT applications running on this
machine before?
Is the development computer a 64bit machine?
The processor is a supported model (See link below).
http://zone.ni.com/devzone/cda/tut/p/id/8239
Regards
Robert
National Instruments UK & Ireland -
How to save a datas from serial port?
How to save a datas from serial port?
Hi
I need some help about rs-232 communication. I want to make a vi witch can do this things:
-read a txt file (to simulate a serial port like when the datas are coming)
i will get 3 different data in serial port (like this: 121 213 135)
i want to save in a txt file what datas get my vi
so
-write in a txt file or draw in a diagram (or both)
so my problem is: read in serial port and save in a file and draw a diagram.
if anybody can help pls HELP ME because im a beginner in this problem.
I already do something but Im not sure that good.
Thx for all. -
Read data from serial port or TCP port of frontend PC
Hello Friends,
I have requirement to read data from device connected to frontend PC which will provide meter reading data.
Vendor has given me two option.
1. Device can be connected to seiral port and data transfer will be done through MODBUS RTU protocol.In that case data need to capture from serial port.
2. Device can be connected to TCP port and Socket program can be provided for data transfer. In that case SAP will act as client and communicate with TCP port.
There will be multiple workstation with individual meters connected to them.
I am aware of text file interfacing through front end tools using custom code using VB,JAVA or others.
Is there any solution availble to achieve above things using ABAP other than text file , like direct communication?
I am using ECC 6.0.Hello,
Socket programming in not available on ABAP, but you may use RFC for the same.
Use the below links for more details
[Link 1|http://help.sap.com/printdocu/core/print46c/en/data/pdf/BCFESDE2/BCFESDE2.pdf]
[Link 2|http://forums.sdn.sap.com/thread.jspa?threadID=1820233]
Regards,
Abhishek -
Count time between 2 readings from serial port... help!.
Hi guys,
I am using my application to get the readings sent by microcontroller from serial port. It works perfectly. But i have the problem, the pic uses 16bits counter, and sometimes i measure frequency lower than 15hz (65535-->16bits). Thats why I thought to measure the time between each pulse that it recieved in serial port. So i could multiply the reading about the time which spend in arrive to serial port. I know if any pulse spend more than 15hz, i should add 65535 to this reading.
Then, the idea is count the time spent between each reading in serial port. SInce pics count and later send each turn.
I dont know if it is possible, and exist any easy way.. Can ayone help me?.
I would like to see any example of it, always it is possible.
Regards, Fonsi.
Attachments:
capture.GIF 19 KBYou're not going to be able to get even close to 1 usec resolution using the built-in time functions though I don't see any of those in your attachment. The windows clock is simply not that accurate. If you need to precisely time your serial reads you might want to look at using the timed loop. You can set the period of that to 1 msec.
-
Never got any response from this forum!!!!
Never got any response from this forum!!!!
PLEASE DO HELP ME, ELSE I WILL BE KICKED OUT FROM MY JOB!!!
I have been encountering the same problem for two weeks, but I couldn't solve it yet since I am using WebLogic not Websphere, and I'm not using SAPJ2EE server.
Running it under Windows, there is no problem. But in Linux, it does. I always encounter,
java.lang.NoClassDefFoundError: com/sap/mw/jco/JCO; nested exception is: java.rmi.RemoteException: EJB Exception:
The configurations are right on LD_LIBRARY_PATH. I mean, the file "librfccm.so" and "libsapjcorfc.so" are being refered. Also the sapjco.jar is set to CLASSPATH.
I am using JCO in Linux and deploying it in WebLogic. I already put the
APP_CLASSPATH=$APP_HOME/sapjco.jar. I guarantee you that the configurations on path and classpath are correct.
Is there anything to do with "application.xml" of the j2ee? Do I need to add some tag there?
I tried also putting the "sapjco.jar" in WEB-INF\lib but it doesn't wiork.
The tag below obviously, wouldn't work for me.
<reference reference-type="hard">
<reference-target
provider-name="engine.sap.com"
target-type="library">com.sap.mw.jco
</reference-target>
</reference>
PLEASE DO HELP SINCE MY DAYS ARE NUMBERED -
Dear All
The 'L' key on my macbook is still not functioning. I got a response from chrisfromhopewell and tried what he said, but its still not functioning. Can someone please assist me. I was using Universal Access before when I had visual problems so this might have caused the problem. but have turned universal access off, so I dont know what else to try. Can someone pleeeze help?
Thanks VeedeekayThanks King_Penguin for taking time to read and reply.
I just purchased this movie on Thursday, May 15, so just a few days ago. I have never had any trouble whatsoever since I have been in Vietnam. I have downloaded several movies and even music and they have all synced to my respected Apple products except for this purchase.
Sorry, I don't quite understand what you mean by studios and different versions. Could you please explain?
I checked my purchased list in my purchase history under my account and there are no hidden items. -
Problem in reading data from serial port continuously- application hangs after sometimes
I need to read data from two COM port and order of data appearance from COM port is not fixed.
I have used small timeout and reading data in while loop continously . If my application is steady for sometime it gets hangs and afterwards it doesnt receive any data again.
Then I need to restart my application again to make it work.
I am attaching VI. Let me know any issue.
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
Attachments:
Scanning.vi 39 KBbillko wrote:
Ranjeet_Singh wrote:
I need to read data from two COM port and order of data appearance from COM port is not fixed.
I have used small timeout and reading data in while loop continously . If my application is steady for sometime it gets hangs and afterwards it doesnt receive any data again.
Then I need to restart my application again to make it work.
I am attaching VI. Let me know any issue.
What do you mean, "not fixed?" If there is no termination character, no start/stop character(s) or even a consistent data length, then how can you really be sure when the data starts and stops?
I probably misunderstood you though. Assuming the last case is not ture - there is a certain length to the data - then you should use the bytes at port, like in the otherwise disastrous serial port read example. In this case, it's NOT disastrous. You have to make sure that you read all the data that came through. Right now you have no idea how much data you just read. Also, if this is streaming data, you might want to break it out into a producer/consumer design pattern.
Not fixed means order is not fixed, data from any com port can come anytime. lenght is fixed, one com port have 14 byte and other 8 byte fixed..
Reading data is not an issue for me as it works nice but I have a query that why my application hangs after sometime and stops reading data from COM PORT.
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--Ranjeet -
Stoping VI inbetween when program seeking data from serial port.
I have an application in which I need to read data from two serial port one after other.
One read will read 14 byte and other 08 bytes(Just info).
Now in between if user need to stop the VI then how to stop it?
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--RanjeetA state machine could do this easily. Just have a state to check for the stop (or any other events).
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Start a program with a signal from serial port
Hi, my program need to continue when it's gets a signal from the
serial port, I've understand that i need to use Java Communications 3.0 API.
couldn't install it.
when i import, in my program, javax.comm.* it can't be resolve.
thank for eny help..:-)Glad you got it to work. I would only say 2 very important things:
1) Do not use an IDE as long as you can't code using notepad and command console and don't understand the concept "classpath". Now you've to learn both the IDE and the Java language basics. This is going to take a longer time than when you learn it one by one.
2) You should NEVER place any 3rd party libraries in JRE/lib or JDK/bin. This is receipt for major future troubles. You should define the classpath yourself. You shouldn't misuse the default classpath. -
How to display raw, not ascii, bytes from serial port?
Hello, I have an instrument that outputs raw data, not ascii, bytes to a serial port. How do you display raw data, not ascii, bytes from a serial port? Since raw data bytes are not displayable, there is got to be something in labview to interpret/display the received bytes the way it is as data in HEX or Binary. The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place. For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code. I am using a VISA-RD function currently to receive the data from a COM port. VISA-RD outputs string type. Thank for any feedback or suggestion in advance.
BC@Baxter wrote:
...The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place...
Of course they are string type, just not formatted in a human readable form. So, YES, these functions are not appropriate.
BC@Baxter wrote:
For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code.
Dennis is right, but there is no "decimal" display for strings, so the second requirement needs a tiny little bit more code.
If you have a single byte string, you can typecast it into a U8 number and set the display format as decimal, hex, octal, or binary as desired. In decimal, it would display the number 77. Since it is now a numeric, you can even do math with it.
In general, the string has multiple bytes, and you would typecast it into an array of U8 numbers (Since this is an often used function, there is also a "string to byte array" which does the same thing).
Typecasting is the secret. You can e.g. easily typecast 2 bytes into a U16, 4 bytes into a I32, 8 bytes into a DBL, etc. For more detailed requirements, there is also the "unflatten from string". Check the online help for details. Good luck!
LabVIEW Champion . Do more with less code and in less time . -
Reading data from serial port needs optimisation
Hi,
We have got a class which reads input from some hardware connected to the serial port.
The data coming from the device can cross over 1mb at a time.
We would like to optimize the speed of the program such that no data is lost during the readings.
Hence, we would like to store the entire reading into memory such that it can be stored into a file or database once the readings have been completed.
The serialport class returns a byte[] of the current data in the buffer. There could be over 8000 such readings.
Would it be better to convert the byte[] into a char[] and append into a StringBuffer
or append the byte[] as is into an ArrayList and perform the conversions and operations on it later?
Reg,
ChetanThe ArrayList will not only be much faster but it will preserve the original data. Unless the incoming data really is a String there is no point in converting it.
Maybe you are looking for
-
trying to activate my iphone 5. when connected to itunes its says i need version 10.7. but when i try to update, it says that im current at 10.6.3.
-
Production Order - Trigger won't Auto Refresh
2007A PL49 - Just upgraded from 2005A I have the following query set in a UDF on the Production Order. SELECT T1.PriceAfVAT FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.ItemCode = $[$-6.0.0] and T0.DocNum = $[$-32.0.0] The qu
-
How do I delete dialogue box asking me if I want to set up Dropbox?
I just got a new 15" MacBook Pro retina display which replaced my 2009 white MacBook. I set up the iCloud for the first time on my computer and I must say I'm pleased! I used to use Dropbox so I deleted my account and thought I deleted it from my c
-
Inserting Video Into My Training
I have some video that was captured as an AVI file and they also put it into MPg4 format. Do I need to convert this into a SWF flash file before I can insert it into my training program? Do I need outside software to make this conversion or will "Pre
-
I have deleted my Mac Air's IP address in Wifi system
Guys! I m really sorry that I think I changed my IP address....You know.....When I try to join with my son's Mac Book Pro by airport......,he just changed the IP address of mine and put his IP address in my Mac Air.....Now cannot connect to INTERNET.