• 13
• 18
• 19
• 27
• 10

# IR through serial port communication

This topic is 4584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm trying to communicate with my multimeter (fluke 189) through IR. I have an IR cable (which came with my TV-card) which is connected on my serial port com1. I followed the instructions on http://www.codeguru.com/Cpp/I-N/network/serialcommunications/article.php/c5395/ and I have the specifications for the communication here : http://www.cfa.harvard.edu/~thunter/manuals/RemoteSpec89_18X.htm but it doesn't work (probably because I did something wrong, offcourse) here's the code :
bool CFlukeDlg::ConfigurePort(DWORD BaudRate, BYTE ByteSize,
DWORD fParity,  BYTE Parity,
BYTE StopBits)
{
{
MessageBox("GetCommState Error","Error",MB_OK+MB_ICONERROR) ;
CloseHandle(m_hComm) ;
return false ;
}

m_dcb.BaudRate =BaudRate ;
m_dcb.ByteSize = ByteSize ;
m_dcb.Parity =Parity ;
m_dcb.StopBits =StopBits ;
m_dcb.fBinary=TRUE ;
m_dcb.fDsrSensitivity=false ;
m_dcb.fParity=fParity ;
m_dcb.fOutX=false ;
m_dcb.fInX=false ;
m_dcb.fNull=false ;
m_dcb.fAbortOnError=TRUE ;
m_dcb.fOutxCtsFlow=FALSE ;
m_dcb.fOutxDsrFlow=false ;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE ;
m_dcb.fDsrSensitivity=false ;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE ;
m_dcb.fOutxCtsFlow=false ;
m_dcb.fOutxCtsFlow=false ;

{
MessageBox("SetCommState Error","Error",MB_OK+MB_ICONERROR) ;
CloseHandle(m_hComm) ;
return false ;
}
return true ;
}

{
if ((m_bPortReady = GetCommTimeouts (m_hComm, &m_CommTimeouts))==0)
return false ;

m_CommTimeouts.WriteTotalTimeoutConstant	= WriteTotalTimeoutConstant ;
m_CommTimeouts.WriteTotalTimeoutMultiplier  = WriteTotalTimeoutMultiplier ;
m_bPortReady								= SetCommTimeouts (m_hComm, &m_CommTimeouts) ;

{
MessageBox("StCommTimeouts function failed","Com Port Error", MB_OK+MB_ICONERROR) ;
CloseHandle(m_hComm) ;
return false ;
}
return true ;
}

bool CFlukeDlg::WriteByte(BYTE bybyte)
{
iBytesWritten=0 ;
if (WriteFile(m_hComm,&bybyte,1,&iBytesWritten,NULL)==0)
return false ;
else
return true ;
}

{
BYTE rx ;
resp=0 ;

DWORD dwBytesTransferred=0 ;

if (ReadFile(m_hComm, &rx, 1, &dwBytesTransferred, 0))
{
if (dwBytesTransferred == 1)
{
resp=rx ;
return true ;
}
}
return false ;
}

void CFlukeDlg::ClosePort()
{
CloseHandle(m_hComm) ;
return ;
}


I have 3 buttons on my form with the following functions :

void CFlukeDlg::OnOpenport()
{
if (!OpenPort("com1"))
{
MessageBox("Failed to open the serial port : com1") ;

}
else
{
MessageBox("Serial port com1 open for communication, now configuring...") ;
ConfigurePort(CBR_9600, 8, true, NOPARITY , ONESTOPBIT ) ;
SetCommunicationTimeouts(0,500,0,0,0) ;
MessageBox("Serial port com1 configured!") ;

}
}

void CFlukeDlg::OnCloseport()
{
ClosePort() ;
MessageBox("Serial port com1, closed!") ;
}

void CFlukeDlg::OnBacklight()
{
MessageBox("Backlight on!") ;
if (!WriteByte('S'))
MessageBox("Failed to write to serial port!") ;
if (!WriteByte('F'))
MessageBox("Failed to write to serial port!") ;
if (!WriteByte(' '))
MessageBox("Failed to write to serial port!") ;
if (!WriteByte('1'))
MessageBox("Failed to write to serial port!") ;
if (!WriteByte('9'))
MessageBox("Failed to write to serial port!") ;
if (!WriteByte('\n'))
MessageBox("Failed to write to serial port!") ;
}


When I run the code, everything compiles fine. I can open the serial port com1, when I press the button "Open port" (=OnOpenPort()) But when I press the button Backlight on (=OnBacklight()) nothing happens. Backlight on = "SF 19 <CR>" (see specifications) My question is am I writing the correct way to the serial port in OnBacklight()? If so, what else could be the problem? Thanx in advance if there is any1 that could help me...

##### Share on other sites
It looks like your code opens a connection to the IR hardware, but may not have a connection with the device. Also, I would have a function to send strings rather than a byte at a time, but that's ultimatly your choice.

There are many things that can be wrong. There are several IR protocols, operating at several different speeds. Assuming the devices you have match each other, you next need to make sure that the IR devices see each other. There might be a minimum or maximum range needed. There might be other issues like the infrared LED getting burned out in an older device, or sensors going bad.

Assuming all that works....

I would start with simpler commands for the device, such as the DS command (default setup) to make sure you get a response and set the device in a known good state. Once I know I can get an ACK from that, I'd move to ID, since it gives more data. At that point, you know you are communicating properly and can just write data however you want. Just jumping in and sending commands to a device probably isn't the best route to take.

frob.

##### Share on other sites

first of all the : Indeed eventually I would make a function that can send a string, but since my application for now is just for trying I thought I would send the commands byte at a time.

Second : The infra red cable is brand new and the multimeter also, so I don't think there is a problem there. But the infra red cable isn't of the same brand as the multimeter. Do you think that could make a difference?

Third : I'm sending the commands first, because that seems to be the easiest route , because if the communication works, the backlight of my multimeter would jump on.
If I send the DS command, I would also have to try to receive from the multimeter. Which is a little bit more coding for me, without knowing if I do the receiving correct.