Sending/reading hex data to a serial port in Powershell

I have a device which responds to serial port requests. Using portmon I can see a request formatted as a six byte hex string.
e.g. x'02031005E6 the last byte being a crc which I can work out.
I don't seem to be able to write this data to a comm port as if I write
[Byte[]] $request = 0x02,0x03,0x10,0x05,0xE6
$port.Write($request)
I see
0.00189600 powershell_ise IRP_MJ_WRITE LSerial0 SUCCESS Length 12: 32 20 33 20 31 36 20 35 20 32 33 30  
where I was expecting Length 6: 02 03 10 05 E6
even if I write
[Byte] $request = 0x02
$port.Write($request)
I get
0.00188317 powershell_ise IRP_MJ_WRITE LSerial0 SUCCESS Length 1: 32  
I have a nasty feeling I am misunderstanding how Powershell handles hex strings/arrays and will assume the sucking of air through clenched teeth on the reply.

Your handling of Bytes, hexadecimal literals and arrays is fine. What type of object is the $port variable referring to?
Edit:  If it's a [System.IO.Ports.SerialPort] object, then the problem is that you're calling SerialPort.Write() with a single argument.  The only overload of that method which takes a single argument accepts a String parameter, and PowerShell
is automatically turning your bytes / arrays into a string representation (which is then being converted back into a byte stream.)
To use SerialPort.Write with a Byte[] argument, you need to pass in 3 arguments:  The array, the offset, and the byte count.  For example:
[Byte[]] $request = 0x02,0x03,0x10,0x05,0xE6
$port.Write($request, 0, $request.Count)
See
http://msdn.microsoft.com/en-us/library/System.IO.Ports.SerialPort.Write(v=vs.110).aspx for more info.

Similar Messages

  • Urgent!!! Need help in file read/write data to a serial port

    Hi,
    I really need someone's help in order for me to complete my project. I have attached a vi which I have taken from an example and integrate to my project. In the vi, I have managed to get the encoder counts using Ni 9411. I need to read/write that data from ni9411 to ni9870 without using any serial port as they are connected to a NI 9104 chasis. May I know whether I am correct in writing the data to my ni9870 port using the vi I have attached? Does anyone know how i can convert the number of counts to a 8-bit data/byte so that I can send the data through the RS232 port? I really need someone's help as I need to finished in 2 weeks time.
    I have also attached an vi on controlling the epos2 controller using instrument driver. Does anyone know how can i integrate this vi to the fpga vi (the one which I need to read/write data to 9870) as I need to send those data to control my epos2 controller.
    Please help me!!!
    Attachments:
    Encoder Position & Velocity (FPGA).vi ‏23 KB
    SINGLEMOTORMODIFIED.vi ‏17 KB

    Afai,
    As I allready suggested you here, call your local NI Office and ask for assistance!
    You really need assistence in a higher level that we can provide via the forums. Otherwise I don't see a chance for you to finish your project in time.
    1. Convert I32 to U8 to write it to the 9870 could be done like this:
    2. The vi to control the epos2.
    There is NO way ( absolutely NO way) to port this vi to FPGA. It's based on VISA calls, uses an event-structure, both are not available at the FPGA.
    The only thing you could do is to analyze the VI, the instruction set and design an FPGA vi which handles the specific instructions you would need.
    I have no experience with epos2 and I'm not 100% sure if this would work as you would like to use it. And doing this needs deep knowledge of LabVIEW, VISA, Instrument Drivers, the epos hardware, FPGA programming, and so on... 
    Christian

  • Hello!!!I need to read some data from the serial port and processing these, at the same time I want to see the process that I am doing.

    I read the data without problems, and I see them using Waveform graph, the problem is that I want to see the real time stamps, but in the graph appears 2:00:00,000 and 01/01/04, so the date and the time is wrong !!
    Can I change this?
    I am thinking that the problem is that I have to adquire the data and the time stamps ( using Get date/time) and after, I have to represent both!!!
    Thanks!!!

    Hello,
    As you probably know a waveform is made of a beginning time (t0), a time difference between each value (dt) and an array of values (Y). Your problem is probably that you don't initialize t0. Use the Vi 'Waveform->Build a waveform' to initialize the time of the waveform.
    Hope this helps !
    Julien

  • Why does a standalone program created in Labview 8.5 try connecting to the internet when the program only reads data through the serial port? Firewalls object to progams that contact the internet without permission.

    why does a standalone program created in Labview 8.5 try connecting to the internet when the program only reads data through the serial port? Firewalls object to progams that contact the internet without permission.
    The created program is not performing a command I have written when it tries to connect to the internet, it must be Labview that is doing it. How do I stop this from happening? 
    Any help would be very appreciated.

    It looks that way..
    "When LabVIEW starts it contacts the service
    locator to removes all services for itself. This request is triggering
    the firewall.This is done in case there were services that were not
    unregistered the last time LabVIEW executed- for example from VIs that
    didn't clean up after themselves"
    This is not yet fixed in LV2009.
    Message Edited by Ray.R on 11-04-2009 12:25 PM

  • I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadshee​t. Any ideas?

    I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadsheet. Any ideas? Right now my data will collect one reading instead of continuously reading my IMU which displays data in a continuous stream.
    Thanks
    Attachments:
    Read_IMU_Drew.vi ‏21 KB

    Hi
    Your vi is in 2009 version, which i am unable to open in 8.6
    However, if you want your data to be saved in excel sheet, here is the VI
    Somil Gautam
    Think Weird
    Attachments:
    save to excel.vi ‏12 KB

  • How can I read the voltage from a serial port

    I am fairly new to LabView and I am having trouble figuring out how to read the DC voltage coming out of an RF Power Supply through a serial port so that I can monitor the voltage every few seconds. In order to do this do I need to purchase a DAQ card or anything like that?

    You would not need a DAQ card to read data over the serial port. You would, however, need a serial port. That may sound sarcastic, but it's not, since many manufacturers are ditching serial ports on computers. If you don't have a serial port then you would need to get something like a USB<->serial adapter or a serial port card that you plug into an expansion slot in your computer.
    Assuming you've got that then you need to find the command set for the RF Power Supply, and write drivers for it so you can send the command to read the voltage, and then read the resposen. I would suggest looking in the Instrument Driver Network to see if a driver for your supply has already been written. 

  • Question about reading hex data

    Hello! I am a Labview Novice and having a problem about reading hex data.
    Basically I am having bytes from the serial port like this: "80100E0E0AB4F646F24A00911267087E032080057FFF "
    It is not encoded in ASCII. What I want to do is to convert the hex to an ASCII hex string.
    so that the string would become hex numbers in ASCII.
    I think the following might be a solution, but I have no idea what the subvi is in the solution.
    http://forums.ni.com/t5/LabVIEW/Hex-String-to-Ascii-Hex-String/m-p/886078/highlight/true#M400462
    Thanks in advance and I appreciate your kind help!
    Solved!
    Go to Solution.

    coolmatthew wrote:
    What I want to do is actually this.
    You are using way too much code for all this. All you need is a concatenate strings, replacing your entire loop and such. Same result.
    (see also)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    HEXTwiddler.png ‏4 KB

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

  • I want to transfer data through the serial port in the same coding that hyperterminal uses. How can i do it?

    The serial port seems to be working, and labview seems to be sending the data, but the problem is in which format does it send the data, because in hyperterminal i just input the string "JDX" and it sends it to my device, with labview it sends something but my device does not recognize it.

    nobuto wrote:
    > I want to transfer data through the serial port in the same coding
    > that hyperterminal uses. How can i do it?
    >
    > The serial port seems to be working, and labview seems to be sending
    > the data, but the problem is in which format does it send the data,
    > because in hyperterminal i just input the string "JDX" and it sends it
    > to my device, with labview it sends something but my device does not
    > recognize it.
    Hyperterminal adds the carriage return/line feed to the string which is
    generated by the return key to send out the current line. LabVIEW simply
    sends out what you tell it, so try to set the string to "Show \ Display"
    format and add a \r or \n or \r\n to the command you want to send out.
    Assumes of course that you set the right baudr
    ate/bits/parity etc in
    LabVIEW with the VISA property node, when opening the serial port.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Need to read Hex data format for Handheld device. (SAP AII RFID )

    Hello,
    we developed a custom screens for packing, unpacking, tag commission.. etc for handheld device for my client. the Serial number field  type is /ain/barcode. Its working fine. but for the new system need to read the Hex format. I created a new field in the screen. but the handheld device is not reading the Serial number in Hex format.
    Could anyone suggest me how to read Hex data in Handheld devices. We are using Motorola MC9090 Series.
    Regards,
    Kamal

    Hi
    Are you using the reader to read an RFID tag or for reading barcodes.
    Ideally, if you read an EPC Gen2 RFID tag, for example, the 96 bit encoded EPC is read and that can be converted to its equivalent  HEX format for posting the observation to SAP AII.
    In case of barcodes, the string is read as is printed on the barcode.

  • Project select data from the serial port

    Hi everyone,
    The project is about use labview to receive data from a serial
    port wirelessly. The serial port will receive two values (X1 and X2) every 10
    minutes. I want to use those two values as two inputs for my formula. How to
    make selection? Many thanks.
    Baicy
    Solved!
    Go to Solution.
    Attachments:
    port read.png ‏23 KB

    Scan From String.
    Using the first option, and putting some numbers in for the zeroes so it shows some kind of meaningful result.
    Attachments:
    Example_VI.png ‏12 KB

  • 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 read and write from the serial port using java

    can anyone tel me how to capture data from a serial port and display on the screen and also store it in a database.

    Java Comm API, JDBC

  • Send 102 bit data through the LPT port??I have to send 102 bit to my interface board using the LPT port, through one of the data line and be able to read data from the input line, I don't know how to realize such a task.Thanks

    Let me describe you the program I have to write:
    I have to send 102 bit serialy using one of the data line of the LPT port to a device and be able to read back data sent from a device register throug one one of the input port pin for instance pin 10 of a DB25, and synchronize the transmission by the PC clock(for write and read). If fact I am using 5 output control(D0...D4) signal from the LPT port, RST, TXD, CLK, CE,TEST, one input data RXD (pin10)
    So the program should work in normal mode (write data, read data), and test mode (use the write p
    rocedure). Since I am quite new in Labview I am little lost and I need some support or exemple that use a way to send more than 32 bit via one data line(in my case 102bit= 8 bit COMMAD(MSB)+88 bit SPI DATA+6 bits CRC(LSB)) and be able to read them back, place them in the register and be able either to monitor or modify them.
    I know that there are plenty of exemple but if I can gain time by being helped it would be great.
    Can you please advise?

    Hi Beni,
    find attached a SPI.vi - minor changed from one of
    my typical SPI's (LabVIEW 7.1). With some simple changes it will fit to your application.
    The only thing you need to do - prepare
    the bits for the input-array.
    If you need some more comments - find one of my email
    adresses in documentation of this vi.
    Regards
    Werner
    Attachments:
    102bit_SPI.zip ‏90 KB

  • Is possible compile .asm code to hex code?? and read&program from lb pic16f84 serial port??

    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

Maybe you are looking for

  • Setting bind references at run-time

    Hi, I am working on a dynamic form,which will instantiate questions based on some instructions specified in XML when the form loads up, much like John Brinkman's example http://blogs.adobe.com/formfeed/2009/03/a_form_to_design_a_form.html At design t

  • Any 3G SIM?

    3G is in many countries but a lot of times there is no "iPad-Specific" SIM (or SIM-plan). Can I use any 3G SIM (eg iPhone SIM) in my iPad Mini (after cutting it to size, if required)? I am asking since I travel a lot and use local SIMs. I do understq

  • Is there a plug-in that provides a better mixing interface?

    Hello, I love GarageBand 2, but was wondering if there might be a way to get a slightly more user friendly mixing interface, with the standard vertical faders. Thanks for any help. Chris iMac G5 2.0 GHz 2GB RAM; PowerBook G4 15 1.67 GHz 1BG RAM   Mac

  • Why always hang for the second put? (MUTEX_LOCK)

    Platform: win32 version: 4.7.25.NC App: multi-threaded db_env: db_env_create(&_dbEnv, 0); dbEnv->setcachesize(_dbEnv, 0, 100 * 1024, 0); flags = DB_CREATE \ | DB_INIT_LOCK \ | DB_INIT_MPOOL \ | DB_THREAD; dbEnv->open(dbEnv, home, flags, 0); primary d

  • My picture gets blurry while streaming

    ANYONE ELSE HAVING THIS PROBLEM IT REALL ***** WHEN WATCHING HBOGO AND NETFLIX