|
I am creating a program for a children's ATM for the local kids museum, and I'm having problems sending data to the machine (over RS232). I am using a .dll supplied by the manufacturer that is used to interface the dispenser with a computer. I think the problem is in sending the hex characters to the machine. I open the port fine (according to the generated log file), but then I send and don't recieve the ACK. I'm pretty sure that it is just not sending for some reason. here is the pertinent part of the code. thanks for any help
#include "stdafx.h"
#include
typedef struct
{
unsigned int uiPort; //communication port
unsigned char ucDataBits; //Data bit
unsigned char ucParity; //Parity bit
unsigned char ucStopBits; //Stop bit
unsigned long dwBaudRate; //Baud Rate
HWND hwnd; //Parent window handle
unsigned char ucCommandType; //command type(1: ezCDM-1000 )
}SETINFO;
typedef unsigned int (*EZLINKOPEN)(SETINFO* setInfo);
typedef unsigned int (*EZLINKCLOSE)(void);
typedef unsigned int (*EZLINKPATH)(PCHAR pcMessage);
typedef unsigned int (*EZLINKSEND)(DWORD dwCmdExcuteTime, PUCHAR pcMessage, UINT uiCmdSize);
typedef unsigned int (*EZLINKRCV)(PUCHAR pcMessage, UINT *piRspSize);
int _tmain(int argc, _TCHAR* argv[])
{
//Loading dll------------------------------------------------------------------------------------------
HINSTANCE hdll = NULL;
hdll = LoadLibrary(TEXT("ezlink")); //load the dll
if (hdll == NULL)
{
printf("Didn't load dll\n"); //tell me if it failed
}
//Mapping the dll's functions--------------------------------------------------------------------------------
EZLINKOPEN ezLinkOpen;
EZLINKCLOSE ezLinkClose;
EZLINKPATH ezLinkPath;
EZLINKSEND ezLinkSend;
EZLINKRCV ezLinkRcv;
ezLinkOpen = (EZLINKOPEN)GetProcAddress(hdll,"ezLinkOpen");
ezLinkClose = (EZLINKCLOSE)GetProcAddress(hdll,"ezLinkClose");
ezLinkPath = (EZLINKPATH)GetProcAddress(hdll,"ezLinkPath");
ezLinkSend = (EZLINKSEND)GetProcAddress(hdll,"ezLinkSend");
ezLinkRcv = (EZLINKRCV)GetProcAddress(hdll,"ezLinkRcv");
//handle the error
if(!ezLinkOpen) //end program if dll mapping fails fails
{
FreeLibrary(hdll);
printf("Failed to map open function!\n");
return -1;
}
else //otherwise, lets send some commands
{
unsigned int result;
//Setting the log path--------------------------------------------------------------------------------------------
char message[] = "C:\\Documents and Settings\\august brower\\My Documents\\Visual Studio 2008\\Projects\\cash machine";
result = ezLinkPath((PCHAR) &message);
printf("Result of Path: '%i'\n", result);
//Opening the port---------------------------------------------------------------------------------------------------
SETINFO pSetInfo;
pSetInfo.uiPort =3;
pSetInfo.ucDataBits = 8;
pSetInfo.ucParity = 2;
pSetInfo.ucStopBits = 0;
pSetInfo.dwBaudRate = 9600;
pSetInfo.hwnd = GetActiveWindow();
pSetInfo.ucCommandType = 1;
result = ezLinkOpen(&pSetInfo);
printf("Result of Open: '%i'\n", result);
unsigned char response[20] ;
UINT *rspSize;
rspSize = (PUINT)malloc(sizeof(UINT));
//Sending commands
unsigned char command[6] = {0x01,0x30,0x02,0x50,0x03,0x60};
unsigned char command9[1] = {0x06};
unsigned char command1[12] = {0x01,0x30,0x02,0x4B,0x42,0x32,0x42,0x32,0x42,0x32,0x03,0x0B};
unsigned char command2[7] = {0x01,0x30,0x02,0x42,0x21,0x03,0x53};
PUCHAR cassette; //check cassette
PUCHAR ack; //acknowledge
PUCHAR bill; //set bill dimensions
PUCHAR dispense; //dispense 1 bill
cassette = command;
ack = command9;
bill= command1;
dispense=command2;
//--get cassette info-------------------------------------------------
result = ezLinkSend(4000,cassette;message,6);
printf("Result of Send: '%i'\n", result);
result = ezLinkRcv(response,rspSize);
printf("Result of Receive: '%i'\n", result);
result = ezLinkRcv(response,rspSize);
printf("Result of Receive: '%i'\n", result);
result = ezLinkSend(4000,ack,1);
printf("Result of Send: '%i'\n", result);
|
|
|
|
|
August Brower wrote: result = ezLinkSend(4000,cassette;message,6);
What is this (it looks pretty ugly, with that semicolon...)?
You know, without knowing proper command format (probably you've some documentation about) we can give little help to you.
BTW: please use <pre> tags (or code block button) to enclose code snippets.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
By looking at following code statements,
unsigned char response[20] ;
UINT *rspSize;
rspSize = (PUINT)malloc(sizeof(UINT));
result = ezLinkRcv(response,rspSize);
it seems like problem with rspSize, rspSize doesn't match with response memory allocatin i.e. 20. I suggest you to try out giving hard-coded 20 instead of rspSize to know exact problem and then after implement generalized logic.
|
|
|
|
|
How to debug a DLL () running on the remote server using Visual studio 2005
|
|
|
|
|
|
Here are some of the steps that mey helps you,
> Run msvsmon.exe located under "Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\x86" on the remote machine where EXE is running.
> Then change the Tools->Options in msvsmon.exe according to your requirements.
> On machine where VS2005 is running, Debug->Attach to Process: Transport-Remote, Qualifier-machine-name:port. Click on Refresh, that will give you list of processes running on remote machine.
Hope this helps.
|
|
|
|
|
On my server visual studio 8 is not installed, It was installed only on my development machine,
how can I go ahead
|
|
|
|
|
Just copy x86 folder on u r server.
|
|
|
|
|
Hi,
I want to know, in a Doc/View MFC application, where is the place to map a message to quitting an application by the File menu and by the X button at the top right of a window ?
Thanks.
Claude
|
|
|
|
|
Hi,
WM_CLOSE would be posted when the X button is clicked or file->exit is chosen. If you can explain your what you're trying to achieve, someone may suggest a better way out.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
You can also use WM_SYSCOMMAND/SC_CLOSE.
|
|
|
|
|
Please reply to the person who asked the query.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
K, will take care about it
|
|
|
|
|
Hi,
I want to convert a 24 bpp image into 8 bit GRAYSCALE image. I have attached the following code snippet to do this .It is not working.
BITMAPINFOHEADER bmpInfoHeader;
BITMAPFILEHEADER bmpFileHeader;
unsigned int extrabytes, bytesize;
RGBQUAD palette[256];
unsigned int numPaletteEntries = 256;
// Fill the bitmap file header structure
bmpFileHeader.bfType = 'MB'; // Bitmap header
bmpFileHeader.bfSize = 0; // This can be 0 for BI_RGB bitmaps
bmpFileHeader.bfReserved1 = 0;
bmpFileHeader.bfReserved2 = 0;
bmpFileHeader.bfOffBits = 0;//sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * numPaletteEntries;
extrabytes = (4 - 320 % 4) % 4;
// This is the size of the padded bitmap
bytesize = (320 + extrabytes) * 435;
// Fill the bitmap info structure
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biWidth = 320;
bmpInfoHeader.biHeight = 435;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biBitCount = 8; // 8 - bit bitmap
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biSizeImage = bytesize; // includes padding for 4 byte alignment
bmpInfoHeader.biXPelsPerMeter = 0;
bmpInfoHeader.biYPelsPerMeter = 0;
bmpInfoHeader.biClrUsed = numPaletteEntries;
bmpInfoHeader.biClrImportant = 0;
ByteArray = new BYTE[bmpInfoHeader.biSizeImage];
while(j < bmpInfoHeader.biSizeImage)
{
if(j < bmpInfoHeader.biSizeImage/2)
ByteArray[j] = 255;
else
ByteArray[j] = 0;
j++;
}
//Write the bitmap file header
UINT nWrittenFileHeaderSize = fwrite(&bmpFileHeader, 1,
sizeof(BITMAPFILEHEADER), pFile);
//And then the bitmap info header
UINT nWrittenInfoHeaderSize = fwrite(&bmpInfoHeader,
1, sizeof(BITMAPINFOHEADER), pFile);
//Finally, write the image data itself
fwrite(ByteArray, 1, bmpInfoHeader.biSizeImage, pFile);
Can u pls. help.
|
|
|
|
|
Member 6042182 wrote: while(j < bmpInfoHeader.biSizeImage)
{
if(j < bmpInfoHeader.biSizeImage/2)
ByteArray[j] = 255;
else
ByteArray[j] = 0;
j++;
}
What are you doing here?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Here ByteArray is an array of image data.I am not sure if BITMAPINFOHEADER and BITMAPFILEHEADER variables are correctly filled.I was trying to put some arbit data on that file.Will you tell me if the BITMAPINFOHEADER and BITMAPFILEHEADER variables are correctly filled?
int i=0,j=0;
while(j < bmpInfoHeader.biSizeImage)
{
ByteArray[j] = GrayData(m_pDrawingSurfaceBits[i++], 0.3;
ByteArray[j] = ByteArray[j] + GrayData(m_pDrawingSurfaceBits[i++], 0.59;
ByteArray[j] = ByteArray[j] + GrayData(m_pDrawingSurfaceBits[i++], 0.11);
j++;
}
m_pDrawingSurfaceBits is a pointer to data elements.
Where I have got m_pDrawingSurfaceBits from the following
CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&m_pDrawingSurfaceBits, NULL, 0);
GrayData is defined in following format.
BYTE CLoadBitmapDlg::GrayData(BYTE b, float Multiply)
{
float a;
a =(float) b;
a = a * Multiply;
b =(BYTE)a;
return b;
}
Is there any code to convert any bmp file to another bmp,in 8 bit grayscale format?
|
|
|
|
|
you need to write the pallete, too.
|
|
|
|
|
how can i give name to my exe module.
|
|
|
|
|
|
You are fast you changed your reply to a link!
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
i mean how can i give a name to my module that can be referenced to check that call to a specific function has come from which module.
|
|
|
|
|
See GetModuleBaseName .
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
On Visual Studio you may specify the name of the executable (if I understand your request). For instance (on VS2005 , at least)
Choose menu Project->Properties and then, select (on the appeared window) the Configuration Properties->Linker node and finally set the Output File property with the intended name.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
this is wat i exactly wanted but there is no output file property in linker options.m using vs2005.
|
|
|
|
|