NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
XiaojunDay
Posts: 2
0 Kudos

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);

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page