0

I have a MT166-C dispenser. I am writing C ++ code to manage a dispenser.

In development use SDK (attach the link) and I have a problem. To work with the dispenser, I open the COM port. Code:

int input_port;
string com_str = "\\\\.\\COM";

std::cin >> input_port;
std::cout << "\nInput COM value: " << input_port << std::endl;

com_str = com_str + to_string(input_port);

char* cstr = &com_str[0];
char* port_com = cstr;

HANDLE port = CommOpenWithBaut(port_com, 9600);

if (port == 0)
{
    std::cout << "Cannot open connect!\n\n" << std::endl;

    return -1;
}

After I use the HANDLE port to call methods.

int iRetn = 0;
BYTE byStatus = 0;

string str = "";

iRetn = MT166_GetStatus(hPortHandle, 0x98, byStatus);

Similar to documentation (p. 3.1 in MT166-C.docx - Link Too)

DLLEXPORT int APIENTRY MT166_GetStatus(HANDLE hComHandle, BYTE CardNum,BYTE &amp;byStatus)
///Parameter:
// hComHandle: Input parameter, serial port handle, obtained by opening the serial port
// CarderNum: Input parameter, card dispenser NO. Default is 0x98
// byStatus: output parameter, card dispenser status word

//Return value:
//Succeed, return value is 0
//failed, return value is not 0 = -1 no communication

In response, I get the code -1 - no communication. For other methods, the situation is the same.

I do not understand why there is no answer from the dispenser (no communication). I would be very grateful for any help. I use connections via rs232 cable or USB adapter rs232 - without change.

Thank you for your time.

  • Are you sure that the port is correct? Are you sure that baud rate shall be 9600? – Dmitry Kuzminov Apr 22 '20 at 21:37
  • Thanks, but the problem is resolved. The device didn`t work correctly, hardware problem. I connected directly to the cardreader and worked with it. Yes, the device works with 9600 and 38400 rates – Sleepy Proof Apr 24 '20 at 07:11

1 Answers1

0
  1. First of all, you need to check the physical availability of an external device.
  2. Check baud speed, data bits, stop bits, row control parameters...
  3. Check the OS hardware list for driver correctness.
sitesv
  • 1
  • 1