Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I send data to device using usbtmc with c#?Are there any examples?

I use USBTMC.
I use VISA Interactive Control to send *IDN?.And it can read infomation from device.
So,I think that the commnunication is no problem.
 
I have some codes.However,it does not work well when writing data as binary.

Sending byte[] abData as following:

visaMbWritersession.WriteBinary(abData,0,abData.Length);
visaMbWritersession.Flush();

However,it stops to send when the value is 0x0A('\n'),but I want to send all of the array.

How can I do?

 

Some codes as following:
        // session
        public MessageBasedSessionWriter    visaMbWritersession;
        public MessageBasedSessionReader  visaMbReadersession;
       
        private MessageBasedSession mbsession;
 
        //Oepn UsbSession
        mbsession = new UsbSession(strSelectedRscName);
        visaMbWritersession = new MessageBasedSessionWriter(mbsession);
        visaMbReadersession = new MessageBasedSessionReader(mbsession);
 
        //read str
        strRet = visaMbReadersession.ReadString();
        // write str
        visaMbWritersession.WriteLine(strSend);
        // write binary data
        visaMbWritersession.WriteBinary(abData,0,abData.Length);
        visaMbWritersession.Flush();

 

The attached is My Usb class.And I use 3 methord to communicate with deivce.
string Read();
bool SendBinary(byte[] abData);
bool Send(string strSend);

0 Kudos
Message 1 of 1
(3,631 Views)