Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are outportb function and inportb function?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What is the outportb function and the inportb function? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The outportb function belongs to the Turbo C (TC) language library function, which is a function output to the hardware port. It seems to be used when learning the C language. There is no this function in C++ now. When I was doing a software specification today, I saw this function. I searched it on the Internet and put it here. In case you use it to find out:-outportb function prototype: void outportb (unsigned char port, unsigned char value) function: output value function to the interface of port address return: function description: port port address File of 8 digits to be exported by value: program example: # include # include int main (void) {int value = 64 Int port = 0; outportb (port, value); printf ("Value% d sent to port number% d\ n", value, port); return 0;}

-

The explanation of the corresponding inportb function is attached.

Function name: inportb

Function: returns an 8-bit binary (one byte) read from the specified hardware port.

Usage: int inportb (int port)

Program example:

# include # include int main (void) {int value; int port = 0x210; value=inportb (port); printf ("port 0x%x sent Value is%d\ n", port,value); return 0;}

In C++, there is no special port read-write function like inportb/outportb,inportw/outputw.

But you can use:: CREATEFILE (. )

Example: BOOL CSerialPort::InitPort (CWnd* pPortOwner, / / the owner (CWnd) of the port (receives message) UINT portnr, / / portnumber (1.. 4) UINT baud, / / baudrate char parity, / / parity UINT databits, / / databits UINT stopbits / / stopbits DWORD dwCommEvents, / / EV_RXCHAR, EV_CTS etc UINT writebuffersize) / / size to the writebuffer {assert (portnr > 0 & & portnr < 5) Assert (pPortOwner! = NULL); / / if the thread is alive: Kill if (m_bThreadAlive) {do {SetEvent (m_hShutdownEvent);} while (m_bThreadAlive); TRACE ("Thread ended\ n");} / create events if (m_ov.hEvent! = NULL) ResetEvent (m_ov.hEvent) M_ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); if (m_hWriteEvent! = NULL) ResetEvent (m_hWriteEvent); m_hWriteEvent = CreateEvent (NULL, TRUE, FALSE, NULL); if (m_hShutdownEvent! = NULL) ResetEvent (m_hShutdownEvent); m_hShutdownEvent = CreateEvent (NULL, TRUE, FALSE, NULL) / / initialize the event objects m_hEventArray [0] = m_csCommunicationSync downevent; / / highest priority m_hEventArray [1] = pPortOwner; m_hEventArray [2] = pPortOwner; / / initialize critical section InitializeCriticalSection (& ShutdownEvents); / / set buffersize for writing and save the owner m_pOwner = pPortOwner If (m_szWriteBuffer! = NULL) delete [] mroomszWriteBuffer; m_szWriteBuffer = new char [writebuffersize]; m_nPortNr = portnr; m_nWriteBufferSize = writebuffersize; m_dwCommEvents = dwCommEvents; BOOL bResult = FALSE; char * szPort = new char [50]; char * szBaud = new char [50] / / now it critical! EnterCriticalSection (& m_csCommunicationSync); / / if the port is already opened: close it if (m_hComm! = NULL) {CloseHandle (m_hComm); m_hComm = NULL;} / / prepare port strings sprintf (szPort, "COM%d", portnr) Sprintf (szBaud, "baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits) / / get a handle to the port m_hComm = CreateFile (szPort, / / communication port string (COMX) GENERIC_READ | GENERIC_WRITE, / / read/write types 0, / comm devices must be opened with exclusive access NULL, / / no security attributes OPEN_EXISTING / / comm devices must use OPEN_EXISTING FILE_FLAG_OVERLAPPED, / / Async iMaple O 0) / / template must be 0 for comm devices if (m_hComm = = INVALID_HANDLE_VALUE) {/ / port not found delete [] szPort; delete [] szBaud; return FALSE;} / / set the timeout values m_CommTimeouts.ReadIntervalTimeout = 1000; m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000; m_CommTimeouts.ReadTotalTimeoutConstant = 1000 M_CommTimeouts.WriteTotalTimeoutMultiplier = 1000; m_CommTimeouts.WriteTotalTimeoutConstant = 1000; / / configure if (SetCommTimeouts (m_hComm, & m_CommTimeouts)) {if (SetCommMask (m_hComm, dwCommEvents)) {if (GetCommState (m_hComm, & m_dcb)) {m_dcb.fRtsControl = RTS_CONTROL_ENABLE; / / set RTS bit high! If (BuildCommDCB (szBaud, & m_dcb)) {if (SetCommState (m_hComm, & m_dcb)); / / normal operation... Continue else ProcessErrorMessage ("SetCommState ()");} else ProcessErrorMessage ("BuildCommDCB ()");} else ProcessErrorMessage ("GetCommState ()");} else ProcessErrorMessage ("SetCommMask ()");} else ProcessErrorMessage ("SetCommTimeouts ()"); delete [] szPort; delete [] szBaud / / flush the port PurgeComm (m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); / / release critical section LeaveCriticalSection (& m_csCommunicationSync); TRACE ("Initialisation for communicationport% d completed.\ nUse Startmonitor to communicate.\ n", portnr); return TRUE;}

The answer to the question about outportb function and inportb function is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report