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
cdl3
Posts: 11
0 Kudos
Accepted Solution

RS-232 via Camera Link

I pieced together some VC++ code to open an RS-232 connection via camera link and send/receive commands. The code compiles and runs, but I am not getting any response from the camera. The command I am sending is directly from teh vendor, so for the moment I am assuming it is correct. Is the code below correct? I would be very appreciative if someone could look over the code below and let me know if I a missed anything. Thanks.

 

I verified that the interface file contains the reference to the camera that I am using and that the camera file is setup to support serial communication at 56 kbaud.

 


  void sendCommand(void) {
    int error ;
    Int32 nSerial, size ;
    char response[9] ;
    char name[64] ;
    char buffer[] = { 0x49, 0x73, 0x65, 0x03, 0x3F, 0x04, 0x00, 0x28, 0x0D } ;  // Sample camera command from vendor
    char text[32] ;

    unsigned int    bitsPerPixel;
    DWORD            dwThreadId;
    
    // Create the event that needs to be signaled when we
    // wish to stop the acquisition.
    HStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!HStopEvent) return ;

    // Create the thread that is responsible for shutting
    // down the acquisition
    HStopThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) StopThread, (LPDWORD) &HStopEvent, 0, &dwThreadId);
    if (!HStopThread) return ;

    // Get the interface name
    GetWindowText(HIntfName, name, 64);    // HIntfName is HWND, or handle to interface = img0, which is correct
    

// Get the interface name
    errChk(imgInterfaceOpen(name, &Iid)) ;
    errChk(imgSessionOpen(Iid, &Sid)) ;
    
    errChk(imgGetAttribute (Sid, IMG_ATTR_GETSERIAL, &nSerial)) ;
    sprintf(text, "%dddd", nSerial);  // Get the index of the serial connection and display in a text box
    SetWindowText (HSerialOut, text);  // HSerialOut is the handle to a text box

    size=sizeof(buffer)/sizeof(char) ;  // # chars in command buffer (9)
    imgSessionSerialWrite(Sid, buffer, &size, 2000) ;  // 2 sec timeout for write (should be more than enough)
    imgSessionSerialRead(Sid, response, &size, 2000) ;  // Same for read

    sprintf(text, "%s", response);
    SetWindowText (HSerialOut, response);  // Do not get any printout and no error messages


Error :
    if(error<0) {
      DisplayIMAQError(error);
      PostMessage(ImaqSmplHwnd, WM_COMMAND, PB_STOP, 0);
    }

       return ;
  }

Member
Tim_O1
Posts: 102
0 Kudos

Re: RS-232 via Camera Link

Hi cdl3,

 

From looking over the code I do not see anything that pops out being wrong. What is the make and model of the camera you are using? After running this code what is in the buffer and response variables?

 

Tim O

Applications Engineer
National Instruments
Member
cdl3
Posts: 11
0 Kudos

Re: RS-232 via Camera Link

Tim:

 

     The code is working; the issue is that both teh serial write and read calls return 0, which I was interpreting as the # of bytes sent and received, respectively. It looks like 0 simply means that the call worked, which I determined was the case by looking at the response. Thanks for your help.

 

  Charles

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