Write to Serial Port without splitting string data

Hi, all, thank you for your help in advance.
Problem:
I am trying to write to the serial port with VISA write module. Somehow the string I tried to send was splitted before it was sent. For example, if I want to send "127", it sends "7', "2", "1". I don't know if there's anyway to configure the module so that it sends out the whole string at once. I use the return count to indicate how many times it spits the data. So "127" now returns "3" (sent three times. I would like to have it to return "1" so that "127" was sent in whole).
Project:
I am working on an application where a DC motor is controlled by a controller talking to the PC's serial port. "127" stands for its maximum power. The controller devides the power into 128 steps. Therefore I need to input number from 0 to 127 to command the speed.
Any help or suggestion will be appreciated!

Thanks for the prompt replies.
About Number/ASCII
I am using the Atmega128-Controller Chip to read in the signals sent from the computer serial port. Then it sends signals to the motor controller. The Atmega chip reads the ASCII string and converts it to hexadecimal number, sending that number to the motor controller. I can program the Atmega chip so that it either translates the ASCII string into hex as mentioned or accepts as it is. Either way, I want it to read two byte information at once (00 to 7F).
If the VISA serial write can send only one byte at a time, then I may have to program the chip so that it buffers the readings. I have tried using number/hex converter and number/string converter, either case, the fact that VISA Write spits one byte at a time hinders the programming. For example: I defined numbers 1 to 5 represents 20% to 100% power output with 20% increment Then I defined "10" as "90%" power, but it reads "1" "0" seperately, so the actual out put is "20%" then "0%".
I used the example VI provided by NI : advanced serial write/read. For convenience, attached here. Not all modification I made is saved.

Similar Messages

  • Write to serial port and digital port at the same time

    hello,
    I need to write to the digital port and the serial port at the same time. Right now I have the two vi's (to write to the serial port, write to the digital port) in the sequence structure. First I write the digital port, then write the serial port. Using the oscilloscope, the interval between these two executions is 10 ms; and I need to reduce this interval to as small as possible. I would appreciate help in any way. Thank you.

    Hello;
    This is a little tricky. Since the transition from one sequence to another is completely Software timed, and windows manages all tasks that are running at one given time, there isn't a method to reduce that transition time.
    The most you can do is try to optimize your code so all the time expent on the transition is due only to the task management.
    Hope this helps.
    Filipe A.
    Applications Engineer
    National Instruments

  • How to export the text edit data to excel file without splitting the data in excel file?

    how to export the text edit data to excel file without splitting the data in excel file?
    I have a requirement in SAP HR where in the appraiser can add comments in the area given and can export that to excel file. Currently the file is getting exported but the comments getting split into deifferent rows.
    I want the entire comment to be fit in one row.
    Please help.
    Thank you

    Hi,
    if your text edit value is stored in 'lv_string' variable.
    then before exporting the value to excel you have to remove CL_ABAP_CHAR_UTILITIES=>NEWLINE
    that is '#' from the variable lv_string.
    for that use code some thing like this.
    REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE in lv_string WITH space.
    I think this will do the trick.

  • Info about read or write a serial port with forms 6.0.5

    Anybody can give some info. on read or write a serial port using form (Developer 6.0.5).
    Thanks
    MM
    null

    One option you can try is to develop a DLL
    function to read/write serial port,
    and then write a ORA_FFI procedure to call the DLL function.
    Peter Ng
    Calgary, Canada
    null

  • Write to serial port asyncronously

    I am trying to write a commands to a serial port but my problem is that the operation is tedious so it is freezing up my UI. What makes it more complicated is that I must call this procedure when the form loads I want to ask if anyone can provide an alternative
    way to get the same or better result I was thinking of running it asynchronously but I don't know how to?
    This is the code I am calling on load
    If lblConnected.Text = "" Then
    MsgBox("Please connect to port.", MsgBoxStyle.OkOnly, "Validation")
    Exit Sub
    End If
    RichTextBox1.Text = ""
    Try
    With SerialPort1
    rcvdata = ""
    .Write("AT" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CMGF=1" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CPMS=""SM""" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CMGL=""ALL""" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CNUM" & vbCrLf)
    Threading.Thread.Sleep(2000)
    Dim lineoftext As String
    Dim arytextfile() As String
    Dim myString As String
    lineoftext = rcvdata.ToString
    arytextfile = Split(lineoftext, "Your number is", CompareMethod.Text)
    myString = "Your number is"
    lineoftext = lineoftext.Substring(lineoftext.IndexOf("Your number is"), 40)
    lineoftext = lineoftext.Replace("Your number is", "")
    lineoftext = lineoftext.Substring(0, 13)
    txtDonglePhoneNumber.Text = LTrim(lineoftext)
    End With
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    I am trying to extract the phone number from this whole routine  and it works but its freezing up my UI. How can I run from another thread.
    If you think it you can achieve it

    Imports System.IO.Ports
    Imports System.Threading
    Public Class Form1
    Private comport As SerialPort
    Private sending As Boolean
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    sending = False
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    comport = CreateComport(comport)
    If sending = False AndAlso OpenComport(comport) = True Then
    Dim t As Threading.Thread = New Threading.Thread(AddressOf SendData)
    t.IsBackground = True
    t.Start(comport)
    End If
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    CloseComport(comport)
    End Sub
    Private Function CreateComport(ByVal port As SerialPort) As SerialPort
    If port Is Nothing Then
    port = New SerialPort("COM4", 9600, Parity.None, 8, StopBits.One)
    End If
    Return port
    End Function
    Private Function OpenComport(ByVal port As SerialPort) As Boolean
    Try
    If (Not port Is Nothing) AndAlso (port.IsOpen = False) Then
    port.Open()
    End If
    Return True
    Catch ex As Exception
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    Return False
    End Try
    End Function
    Private Sub CloseComport(ByVal port As SerialPort)
    Try
    If (sending = False) AndAlso (Not port Is Nothing) AndAlso (port.IsOpen) Then
    port.Close()
    MessageBox.Show("Port closed")
    End If
    Catch ex As Exception
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    End Try
    End Sub
    Private Sub SendData(ByVal port As Object)
    Dim buffer(1023) As Byte
    For i As Int32 = 0 To buffer.Length - 1
    buffer(i) = i Mod 256
    Next
    sending = True
    Try
    DirectCast(port, SerialPort).Write(buffer, 0, buffer.Length)
    Catch ex As Exception
    CloseComport(DirectCast(port, SerialPort))
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    Finally
    sending = False
    End Try
    End Sub
    End Class
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • Cannot write to serial port

    Hi,
    I am using jdk 1.3.1, forte ce 3.0 and j2me 1.0.3 beta.
    I wrote a midlet that should write and read strings to and from the serial port.
    Using the Emulator I have the reading working, but the writing freezes the execution.
    Any ideas?
    Debbie

    Thanx for your reply (I have been asking this question everywhere for 2 weeks and no one has answered...).
    I am using the Motorola i85s. It is specifially stated in the "i85s & i50sx Release 2 J2ME Developers' Guide Addendum" that the serial communications SHOULD work.
    As I said - reading from the port (using the i85s Emulator) works - but writing to the port - freezes the execution. So this means that my connection is up and running - just the write is not working.
    I would love to be able to load my midlet to my phone - since maybe on the phone it WILL miraculously work. But in this direction I am stuck with the fact that the JAL Lite does not load "network capable apps" - whereas I cannot get my hands on the Web JAL (which DOES load network capable apps) - since I have not succeeded to get thorugh the 100 steps that you must go through in order to use it... see for yourself at https://idenonline.motorola.com/ideveloper/program/program_jal.cfm).
    Help...?

  • How to read serial port only when new data has been sent to it

    I've written this very simple vi to read the serial port whenever the MKS Helium Detector sends a new value.  The timing of new data is controlled directly from the front panel of the MKS instrument.  I thought it was as simple as looking at the "bytes at port", and reading the port only if the value is not zero.  The problem I'm having is that the read function is occuring whether I want it to or not.  Consequently, the "Scan from String" function is returning an error (0) once in a while, because it's reading the serial port as it's being updated (I think).   Apparently, when the port is in the process of being updated, it is not zero.   Anyway, I'm assuming there is a simple fix, but I'm having no luck finding the Easter egg.  Any help would be, as always, very much appreciated. 
    Attachments:
    MKSRead.vi ‏55 KB

    You can approach your problem in a couple of ways. The way you've got it written now, as soon as the number of bytes is non-zero, you read and convert. This means that when a partial string is there, you conversion is nor correct. One way is to wait until non-zero bytes like you do now, and then in another loop, read until the byte count is equal to zero and then do the conversion. You can also read until the cr\lf is detected and then do the conversion on the string. You can also enable the termination character for the read but then you'll have to increase the number of bytes to read to something other than just the number of bytes first available. If the instrument always returns the same number of bytes, you can use that as a constant for the VISA Read. Then the read will terminate whenever the byte count OR the termination character is detected.
    I modified your VI to show you how you might put it in a loop and what for the CR/LF to be detected. You would want to add a timeout to this so that if the character does not show up, the loop will not run infinitely
    Attachments:
    MKSRead_mod.vi ‏68 KB

  • First line from serial port, partial or junk data

    I'm trying to receive the following protocol which works, except I have to insert the equipment while the serial port is sending data.  So sometimes the first line is partial data and that causes errors down the line.    My thought was to wait to receive data until I receive the &&\r\n0108.  Any suggestion or code to implement that would be great. 
    Here is a couple of sample packets:
    &&\r\n
    0108136.19\r\n
    0110146.19\r\n
    01130.35\r\n
    012350.00\r\n
    !!\r\n
    &&\r\n
    2350155.19\r\n
    !!\r\n
    TIA,
    Jerry
    Attachments:
    Read_and_Parse_Data.vi ‏22 KB
    Strip_data.vi ‏12 KB

    Hey Raptor50,
    I would recommend using a queue to take in the data and then build an array and then trigger some event to start off of the &&/r/n0108 after this line is found you can proceed normally withou any lose of data.
    These may help:
    http://decibel.ni.com/content/docs/DOC-15453
    http://decibel.ni.com/content/docs/DOC-8653
    Sam S
    Applications Engineer
    National Instruments

  • Can I reset serial ports without rebooting?

    I have an application that communicates with a SilverMax servo drive over RS232.  If the device is off when I run my VI or if it gets turned off during a program run, the serial port locks up at the VISA serial write VI.  I need to hit the reset button on the PC to recover.

    Hi TAS1,
    Try the Basic Serial Write and Read Example VI, and see if the example works.  You can find the example in the NI Example Folder, which you can access by navigating to Help » Find Examples... in LabVIEW.  The behavior you described is unexpected.  Make sure that there is a delay, as shown in the example, and that the VI executes all the way to the end, where there should be a VISA Close.  It is important that VISA Close executes, because this clears the VISA resource.  Please let me know if you have any questions about the example.
    Regards,
    Rima
    Rima H.
    Web Product Manager

  • String.class without split(String regex)

    hello,
    This is my problem:
    I am using eclipse with j2sdk1.4.2 which
    implement
    the clase String.class with
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    PAth: home_j2sdk1.4.2/jre/lib/rt.jar 25.762kb
    In this way:
    String columns[] = line.split("\t");
    for (int i=0; i<columns.length; i++)
    ws.addCell(new Label(i,row,columns.replaceAll("\"","")));
    I move the code above to websphere Application Developer 5.1.2
    which use Home_Websphere/eclipse/jre/lib/rt.jar 8.827 kb
    this jar in yours String.class not contains the
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    I need to find the use my code above with that methods,
    what i need to do ???
    possible,i need to find the source to String.java of j2sdk1.4.2
    which implement the methods, but where ???
    or there is another way to do it ???
    Any help is greatly appreciated.

    If websphere is supposedly 1.4 compatible, arethey
    "allowed" to leave out methods from the JFC? Not sure what the JFC is, but no, they would not be
    allowed to leave out any methods.
    JFC - Java Foundation Classes. I think they started calling what might be considered the Java Core the JFC when they first added Swing to the distribution. Maybe the term is no longer used.
    RRD-R      
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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.

  • How do I monitor serial port activity without first sending a command?

    In my application I am sending a command through the serial interface and I want to monitor the response. The response is not instant, in fact it is a timeout response indicating the requested action did not work. How do I monitor so I can parse what is coming in over the serial port without necessarily sending a command?

    You can always place a loop where you monitor the number of bytes at the serial port.
    After configuring your VISA serial port session, you can create a Property Node to get the number of bytes available at serial port.
    You can then process this information, for instance:
    1. Establish a timeout because you never get a response.
    2. Do serial port read if there is data available.
    You can exit the loop with a timeout condition or having processed the data.
    -JLV-

  • Esc Command to serial Port

    I'd like to send an esc command to the serial port in my LV-application. how I can do that ??
    I tried to use write to serial port and \1b as string but it not worked.
    In a terminal programm it works with the ESC key and with ALT+027.

    Hi,
    You have to be careful with the kind of datas that you send...
    You told that you sent \1b or something like this, but did you sent this in Ascii mode or \ mode... It's very different for the device...
    Maybe you have to write as a constant in \ mode the code \1b, and after that convert this string type to ascii mode using the roght button on the constant and then send the character to the device

  • Need help to solve problem regarding Serial/USB want to get data on event base

    Hello This NI Forums have helped me a lot in learning the Labview, every time I am in problem people on this forums have helped me.
    Actually I need some example VI which could guide me to solve my problem.
    I want to get data on USB speed 1mega and should be event handled means when every a byte is received at com port ( which is always Hex value)  should be written in text file without the loosing the data.
    Thanks in advance 

    1. Use polling. Use the "Bytes at Serial Port" to read the data.
    2. No way to write each byte at a file at this speed . Store them in an array and every some time write the file and empty the array.
    3. If you can start with lower transfer rates and then go up to 1Mbps.

  • Is it possible to choose the serial port if only the run time engine is installed

    I have an application, which communicates over the serial port. When I use the full version of Labview I can change the serial port without any problem from Com1 to Com2 (similar to the example “Hardeware input output -> serial -> Labview serial vi"). When I build an application and try to run this program on a computer where only the run time engine 6.1 is installed, it is not possible to choose the serial port. Since there is no “Measurement and Automation Explorer” available on the run time engine and no directory C:\VXIpnp is created, when the run time engine is installed, I do not see a way, how I can satisfy the computer with the information it needs for configuring
    the different ports. Any suggestions?

    Hi Daniel,
    Before LV6.1 there was LV5.1 In LV5.1 the way to Spedify a resource was to use a string control with correct VIsa Resource Class identifier. For eg. "GPIB0::11" or "ASRL1::INSTR". With Introduction of VISA Resource Name Control and linking with MAX, These names are Available from Pull Down List and Can be Aliased, meaning ASRL1 which is Serial Port 1 can be called COM1 and so on. However the old method still works with all 6.1 Controls. Only thing is you have to make sure you Dont Conflict the Class Names ie Use "GPIB::.." instead of "ASRL..." when addressing Serial Port VI's.
    To solve your Problem I would Build a Menu ring with COM1 to COM4 in the Pull Down List.
    Next, If I use the Traditonal Serial Port VI wich accepts the Integer as Seria
    l Port #. I just Wire the Menu Ring to this VI.(Remember COM1 is 0, COM2 is 1 for this VI)
    If I use VISA Config Serial Post. I build an Array Constant with Corresponding VISA Class Names So in our case a String Array Constant of 4 elements "ASRL1::INST" to "ASRL4::INST". I Use Index Array Function With the Index Wired to my Menu Ring. The Array Input Terminal Wired to the Array Constant. The Output of this Array will be correct Visa Class Name Based on slection of my Menu Ring. I can Wire this as Input to my VISA Config Serial Port Vi.
    I have attached a Small VI to Illustrate this.
    Drawback: You must Predefine what Ports you will Want to Use. Basically you define all the cases.
    I hope this Answers your Q!
    Good Luck
    Mache
    Good Luck!
    Mache
    Attachments:
    Serial_Port_Select.vi ‏36 KB

Maybe you are looking for