Serial Port Code
Has anybody got any code that simply opens a COM port and reads information from it - into a file or something. Nothing fancy with GUI's or anything like that. Cheers.
Just download COMM API from http://java.sun.com/products/javacomm/index.html
unpac them, install & take a look at samples folder.
Look ofr SimpleRead.java and SimpleWrite.java - they are good start.
Similar Messages
-
How can I autoindexi​ng data from vi that read the serial port (CODE)
Hello. I´m working in a proyect in the company, the proyect consist in read two incremental encoders for the inspection of automotors supension. I have a Digital Read Out System that read the 2 linear encoders, the DRO it has a serial RS-232 interface, i can read the data from the DRO to my computer, but now, I want to storage the information in Arrays (for autoindexing) for then make a graphic, If you want check the program, and if you tell me information, or a example code thanks for yor help.
P.D. Only if the data is diferent is sotraged. (I have LabVIEW 5.1.1)
Atn. Ing. Jorge Cardozo. San Luis Rassini Corporation. Piedras Negras Coahuila Mexico.
Thank you for your help.
Attachments:
KA-COUNTER (Comparacion).vi 77 KBhi there
to collect scalar data in an array you can use a so called "Shift register". To display the history of scalar data you can use a Waveform Chart (not a "Graph", a "Chart"). See attachments. because i can't save the vi as 5.1 i appended some screenshots of the front panel and the block diagramm.
Best regards
chris
CL(A)Dly bending G-Force with LabVIEW
famous last words: "oh my god, it is full of stars!"
Attachments:
KA_Counter_BD.JPG 122 KB
KA_Counter_FP.JPG 86 KB -
Pc to h/w communication by using serial port
I have write a serial port codding but thre is problem in accessing the javax.comm.*' packege.
I had downloaded that package on my pc but its not working.
Could anybody help me?Hmm. Urgent. When is your project due? What have you tried so far? Whats not working? First you need to verify that all your hardware is connected properly and the UART is properly configured on teh 8051. Then you need to make sure that the software on both the PC and the 8051 are both working properly. Just curious, what class is this project for?
-
Problems with access to serial port using reentrant code
Hi,
I have a VI that send commands and receive answers from an instrument using
de serial port.
This VI runs perfectly when used alone.
However I'm trying run two instances of that VI simultaneously using
reentrant code and I'm facing some problems.
Sometimes everything is OK but sometimes, in the process of writing to
serial port the following error happen:
Error code 36.
Invalid refnum device.
What is this?
Does someone know how to prevent this?
Thanks in advance for any help."Paro, Paula [CMPS:2721:EXCH]" wrote:
>
> Hi,
>
> I have a VI that send commands and receive answers from an instrument using
> de serial port.
> This VI runs perfectly when used alone.
> However I'm trying run two instances of that VI simultaneously using
> reentrant code and I'm facing some problems.
> Sometimes everything is OK but sometimes, in the process of writing to
> serial port the following error happen:
> Error code 36.
> Invalid refnum device.
>
> What is this?
> Does someone know how to prevent this?
>
> Thanks in advance for any help.
You can't use reentrant vi's vith serial vi calls without supervising of
driver.
Use VISA instead and you have to control the VISA session opening and
closing. Another word is that the only one serial port sess
ion should be
opened at a time.
Reentrant vi's for serial port without checking serial port session is a
mistake of program algorithm. Change it in any convenient way.
Sergey Krasnishov
Automated Control Systems
National Instruments Alliance Member
Moscow, Russia
[email protected]
http://acs.levsha.ru -
Sending an ESC code using the serial port
I have a motor control aplication that requires sending an ESC character using the serial port. LabView has several built-in functions (end of line, line return, etc.) but I just do not know how to send this particular code using the serial port. Any ideas?
The hex code for ESC character is 1b, Try writing it in a 8 bit unsigned number and then change that byte to charachter using labview function "byte Array to string". In this way you can pass this charachter.
-
Hi,
I would like to use my aplication, i use a pic 16f84, in my vi application i modify the asm code, and save it. LAter i need to use mplab to compile to hex and use icprog to pass to the pic by serial port...
Is possible do all on labview???.
Or maybe call the mplab directly to open and convert to hex file, and later call the icprog to program the pic.. without use this programs. Directly with commands do it and close the programs...
I hope any help..!
Regards, Fonsi.Fonsi,
You certainly could write an assembler for the pic code in LV. I wrote an assembler for the old 6502 processor in LV4. The project got cancelled before everything was finished, but the concept is valid. It is a lot of work, parsing strings and tracking all the addressing modes, etc.
Whether it is worth the trouble as opposed to using the existing tools is something you will have to decide.
If the other software can be called from a command line, the system Exe.VI might be useful.
Lynn -
Create and Send an array of hex code to a device through serial port
My name is Tina Drew,
I am working programming a project involving an RFID system. In order to get the project to work the way that I desire, it must send a hex code of 01 to start the device and 6A to run in continuous mode. I have part of the program by the device does not appear to be responding to the hex signal. Maybe my programming is incorrect. In addition, it will not read the information from the microreader through the serial port. It says that the time has expired before the operation can be carried out. What should I do? A sample of the program is attached.
Please contact me as soon as possible at 410-651-7604 or [email protected]You forgot to attach your program. It happens to the best of us. I sure wish NI would move the darn attachment button next to or before the submit button.
Things to check:
Baud Rate
Number of stop bits
Parity bit
DCE device talking to DTE or vice versa. If both devices are DCE or both DTE, you must use a null modem cable.
You can use Hyperterminal to see if you can communicate with your device manually (On the hyperterminal screen, hold down the Alt key and type 001 from the numeric keypad, not the numbers from the top row above the letters, a smiley face will appear if the device echos back the character. If it don't, you can setup hyperterminal to display the character - look under file-properties-settings-ASCII Sending-Echo typed characters locally). If you receive a good response, this will tell you if you have the correct baud rate, etc... After proving that this works, make sure your vi's serial port configuration match your hyperterminal settings. You can use a breakout box to determine if you have a good DCE-DTE match. DCE will assert the RS232 signals DSR, CTS, and CD. DTE will assert DTR and RTS. By hooking up a breakout box on one end of the com link, you can see which LEDs are on and this tells you whether you have a DCE or DTE. Most computers are DCE. Modems are DTE. Your device would have to look like a modem to the computer as far as RS232 signals go.
- tbob
Inventor of the WORM Global -
Serial port control -- what's this code snippet?
Hi, all.
I've just become active working with LabView, version 6.0i. And this because of a program which "suddenly" stopped working, with no changes made by anyone that I can see (yeah, likely story, right?).
In short, the screenshot which I'll include with this post is of one tiny code snippet buried deeply in the .vi which runs an X-Z positioning system. I'd like to know what people thing this code snippet does. I have my suspicions, but I can't believe that whoever wrote this code actually used it for this purpose!
The X- and Z-positioners which I'm using are controlled by separate power sources, and separate ports on the computer. The X-positioner is ultra-fine-resolution, and has an optical encoder. It's controlled by the RS-232 port on the computer, and it's meant to be moved only a little at a time. The Z-positioner is a bit more coarse, and usually moves quite a bit at a time. It's serial-port controlled.
The screenshot is of the portion of the code called "XMove" -- that portion of the code which controls the x-positioning stepper motor. Often, the Z-positioner is still running during this part of the code (the "ZMove" subroutine is called before the "XMove"), and then, after both parts of the positioner have stopped, the code should shut down the power to them, and update the position of the translation stage.
However, once the code gets to this portion (screenshot), that while loop just keeps running.
Here's what I think is happening (please correct me if I'm wrong!): The Z-positioner is run by the serial port, which, as far as I know, can be controlled by only one device at a time. Thus, this While loop does the following:
1) attempts to write the characters "1R" followed by a linefeed to port 0 (the applicable serial port on this computer);
2) reads how many characters are stored in the serial buffer;
3) reads all the characters in the serial buffer;
4) takes the first two characters from the string read;
5) compares these two characters to *R;
6) if the two characters are R, then the loop terminates and the code finishes.
As far as I can tell (I've probed many parts of this structure), the code fails when the "N" portion passes the number of characters in the serial buffer to the "R" portion -- it's always zero. It appears to me that the "W" portion writes to the buffer AFTER the number of characters is read (I wouldn't have suspected this unless I'd run it many times and monitored which steps were done in which order). This ain't right!
I found a similar question answered in the KnowledgeBase forum, but the answer to that one was that the serial port may have an "echo" mode. That doesn't change the fact that data is being from to the port before it's written, does it?
Is there a way to make sure that the "read" statement happens AFTER the "write" statement? Am I way off base with what this code snippet should do? And, most importantly, *** is this a good way to tell if the Z-positioner is done with its job? ***. Is this a standard trick to tell if a program is done with the serial port?
Thanks, all. I know the quandary of trying to debug with so few details, and not having the program in front of you. Any help is appreciated!
Sincerely,
Curtis Osterhoudt
Attachments:
VI_diagram.jpg 17 KBI suspect someone did change it, but they just don't realize they did.
THe code snippet is an example of some very bad LV code! What you suspect is happeneing is indeed true. LV uses a data dependacy paradigm that says code execution order is dependent on data availablility. Data availability is determined by ythe rule that the output of a node or sub-VI is not available until the object completes.
In you snipet, the only node that has to complete before the read bytes at port and the write to port VI is the the constant port number constant. That means that LV can execute either the write or the check bytes at port VI's first. This is determined at LV compile time. If for some reason LV decideds to compile in the write before the check bytes at port, the
n the I/O may work as intended, BUT NOT POROGRAMMED!
For a quick fix, put the contant port number and the write VI in a single frame sequence structure. This way the read from the constant and wire operation must comlplete before the seq completes, therby forcing the read stuff to wait.
I hope this help,
Ben
Ben Rayner
Certified LabVIEW Developer
www.DSAutomation.com
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Reading ascii codes from serial port and plotting them
Hello
I am trying to build a VI that reads data (ascii values) from the serial port.
I am trying to build a wireless phonocardiogram. I have a microphone that acquires heart sounds. these signals are amplified and sent to a A/D converter to digitize them. the digital signal are sent to a base unit. The digitals signals received at the base unit have to be sent to a computer (over a serial port to view them).
I would like build a VI to plot ascii data received over the serial port.
I would like to plot those values so that the plot just looks like a analog signal (the one I had before A/D conversion).
Can anyone provide me some help?
Thanks in advance.....
Solved!
Go to Solution.Hi chaitu209
What is your transmission speed, samplerate, and bandwidth needed in your project? The bandwidth of the serial port is somewhat limited. Let me give you an example
Say you are using 115200 Kbit per second as transmission speed, one start bit/stop bit and parity bit, and 8 bit data. This will give you 115200/11 bytes pr second as the maximum theoretical transfer rate/sample rate. But if you are using up to 16 bit AD your maximum samplerate will be 115200/(2x11). So my advise to you is to use a binary transfer protocol not ASCII based protocol. This is not a problem in Labview with serial transmission.
Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far) -
How do I process serial port strings as bits
In response to my commands, my instrument is sending bytes to my serial
port. In one instance, 2 bytes are received. I want to treat these 2 bytes
as a group of 16 bits.
The VISA and Compatibility Serial functions return these bytes from the
serial port to Labview clearly labelled a "string".
Everything I can find in the way of Labview functions and .vis don't want to
do bit twiddling, bit swapping, and bit dropping, with "string" data.
I thought "hex string to number" could be used here, but I can't find a way.
The 2 Bytes in question can be represented as hex, but the data are not the
ASCII codes for the hex representation of a binary number, they are the
binary number. This "hex string to number" seems to want ASCII c
odes.
You can feed a hex number typed into a "control" box wired into "hex string
to number" and you get a meaningful number. You can feed the 2 bytes from
the serial port into an "indicator" set to read in hex and you get a hex
number that is a correct representation. But that is Labview handing them
around to itself. I need to get my "hands" on them.
I can't feed those same bytes that show up as a correct hex representation
in an indicator into the "hex string to number" or anything else, so far,
and get a number that is useful for further processing.
I thought "variant to data", but I can't find enough reference material to
understand how to use it. A boolean array seems like a bit of a weird
approach, so I thought I'd ask before I looked into that.
I'm used to dealing directly with binary numbers on the processor stack, I
call them whatever I want, and turn them into anything I feel like.
I'm sure I'm staring the solution in the face, but I can't find any way to
persuade
Labview to treat this "string" data as 16 bits.
I've got the 16 bits, which is better than not having them, but I don't have
much hair left.duh, well I finally discovered the "Unflatten from String" function. A guy
just feeds in the bytes he's collected from his serial port that Labview
thinks are a "string", and out come lovely little unsigned 16 bit numbers,
or whatever other type of number he wants to turn the bytes into. And there
are great little bit twiddlers available after that, like "swap bytes", and
you can mask out bits with the logic operators, why this is fun. There's
nothing like being a moron...... fly me to the moon...................
"David Lewis" wrote in message
news:[email protected]..
> The two bytes would come from a serial port read.vi in Labview, classed as
a
> string. For instance, D3 and 02. The output wou
ld swap the two bytes,
i.e.
> to 02 and D3, consider the two swapped bytes as 16 bits, drop the six most
> significant bits, and output the ten bits that are left as an integer
> classed by Labview as some kind of number, not a string.
>
> Your example StringToBits_Converter.vi I found on the ni.com site
> unfortunately gives an error message and refuses to open on my system
saying
> it comes from a newer version of Labview 6 than I am running. Mine says
> 6.0.1b3. Thank you very much anyway.
>
> "FightOnSCTrojan" wrote in message
> news:[email protected]..
> > In another words, you want to create a VI in which the input is 2
> > strings (i.e. AB) and the output is the converted array bits (e.g.
> > 1010101010101010)?
>
> -
KM2M serial port not working in Linux
I noticed a few Linux postings so I thought I'd give this a shot. I'm running Fedora Core and for some strange reason I can't seem to send any communications out to the ttyS0 (COM 1) or ttyS1 (COM 2) ports.
Does anyone have any suggestions on making it work?
Thank you.No, your code had no termination characters at all - automatic or not. The enable termination character for the VISA Configure Serial Port is only for reads. Just like the help explains.
And while you should check the download page for updates, LabVIEW comes with the 34401 driver.
Message Edited by Dennis Knutson on 12-19-2009 05:49 PM -
Problem in using serial port.
I am using serial port to get data from a fusion splicer. The number of bytes at the port is 4096 but the read buffer of VISA read is empty. I am reading the same number of bytes. Can any one tell me what is the maximum size of VISA Read buffer? I am trying to put the contents of the buffer in a file. I am using labVIEW 6.1 on linux.I am also attaching the VI.
I also noticed this problem...If I read the number of bytes in the serial buffer many times, sometimes it reads it as 0 and I have to keep trying until it reads this 4096 bytes.
Thanx for any help.
S.Vijayalakshmi
Attachments:
serail_comm.vi 52 KBHey Viji,
In your application it looks like you are just checking to see how many bytes are at the serial port. Is it possible that your application is check for the serial data at the port before the data actually gets there. If you are looping this code as a subVI or just running it over and over it is possible that one of the iterations could occur faster than your device can write the information to the bus. In this instance you are checking the number of bytes at the port and there might not be any there yet. In this case the port reads 0 as you have designed it.
If you want the read function to wait and always read 4096 then don't wire the bytes at port to the read function. Just wire a constant/control equal to 4096 to the read function instead o
f the bytes at port. In this case, if there are not any bytes at the port the read function will wait for the bytes to show up or until the timeout period is reached.
I would also, suggest lowering your time to something more reasonable, because if your instrument quits transmitting your application is going to wait for 33 minutes. That is a long time for a program to hang.
I hope this helps out.
JoshuaP
National Instruments -
Help with reading information coming from a software into LabVIEW through Serial port
Hi,
I am new to LabVIEW and also an amateur in using RS232 for communication. I have this software that has these icons like speed increase/decrease, elevation up/down, start/stop. Now, when I click these buttons on the software, they perform the appropriate functions. For example, if I press start button, the signal must go through a serial COM port into LabVIEW to start the machine. How do I do that? How do I find what format the code word is when I press a button on the software? And how to decode the information to read whether the button pushed is start etc...? Any help would be appreciated.
V
I may not be perfect, but I'm all I got!That information would be in the programming manual for the device you're controlling. Unless you have a device that has no documentation or you cannot get the documentation that's the first place you should look. If you cannot get the documentation at all then you've got some reverse-engineering to do. To do this you will either need a serial port sniffer (a hardware device), or you can try to use a software-based port capturing program. On Windows PortMon is the most prevalent. This will show you how the port was configured (baud rate, stop bits, etc). Warning: the information is technical.
As far as how to get it running in LabVIEW, you should take a look at the serial port communication examples that ship with LabVIEW. The most problems occur in figuring out how to (a) terminate a write command, and (b) determining when to stop reading. For (a) this is typically done by appending a carriage return or linefeed to the command. This is device dependent. For (b) this is usually done by the byte stream ending with a character like a linefeed. Again, this is device-dependent.
You may also want to peruse this KB article: Serial Instrument Control Tutorial. There are also lots of tutorial on the internet for basic tutorials on serial port communication. -
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. -
How can I read a serial port using XCode?
Hello,
I'm using an iMac 2009 with Mac OS X 10.6.7. I have a USB to Serial cable and I want to connect a hardware I made using a microprocessor Microchip PIC to my mac. I'd like to read values from the serial port and also write values to it. I'm already able to do this using the Terminal with the following command:
screen /dev/tty.usbserial 9600
I'd like to build my own application now. Does anyone could send me any sample code?
I'm using XCode 3.2.5 and I'm a beginner on XCode.I looked at Dev Center for sample code, and I found this link:
http://developer.apple.com/library/mac/#samplecode/SerialPortSample/Introduction /Intro.html%23//apple_ref/doc/uid/DTS10000454-Intro-DontLinkElementID_2
I downloaded the sample Xcode project and, when I click on "Build and Run" button, it generates an error with the following message:
"GCC 4.2 is not compatible with the Mac OS X 10.4 SDK (file SerialPortSample.c)"
Maybe, it occurs because the code is too old (2005). I didn't find any newer sample.
Could you help me?
Thank you.
Maybe you are looking for
-
I recently got an Ipod touch for christmas and decided instead of upgrading my itunes to just delete it and install itunes 9. However, whenever I install it an error message pops up: "An error occured during the installation of assembly 'microsoft.VC
-
I have used Photoshop 7.0 for around 6 years and upgraded to CS5. I did the trial download for 30 days and when working with layers if I clicked on the layer to move it around, it would disappear *poof*. I'd have to hit Ctrl-T and I could usually loc
-
IPhoto 9.6 won't play videos but does give distorted still
I just installed Yosemite and upgraded IPhoto as required, with rebuilding of library. Mid-2010 Mac Book Pro with semiconductor drive. Still photos are fine but some newer videos don't play and I get a message "OSS status -54". Older videos taken on
-
I receive an error when installing LVRT 7.1. I am running LV8.0.1
The error shown in the attached jpeg appears when I try to install LVRT7.1 (ETS). I am running LV 8.0.1. Suggestions? Attachments: LVRT Instation error.JPG 22 KB
-
Fascinate won't start unless plugged in
My Samsung Fascinate won't start unless plugged in. Even with a full battery. It shows a dead battery and won't start.