|
This would be better in the Visual Studio forum; it is not a C/C++ issue.
Veni, vidi, abiit domum
|
|
|
|
|
Understand, you are correct. Thank you.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Hi to everyone. I want to write a programm that opens a cash drawer. How can i change the value of the 2nd bit of a register? The register's address is 4B8h and it's size is 8 bit. Can anyone help me with an example?
|
|
|
|
|
To flip a bit, you can use XOR (exclusive OR). If the target bit is off, this turns it on, and if the target bit is on, this turns it off.
Here is an example:
register = register ^ 0x02;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Do you mean that in the address 4B8h i will use XOR to change the 2nd bit to 1 that opens the cash drawer and then set it back to 0? Sounds too easy.
|
|
|
|
|
Well, you asked how to flip the bit, and XOR is the way to do that.
You can read about it here: XOR[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Read the current value of the register, flip the bit, write the new value back. You omitted to mention how or where you are accessing this register so it is difficult to be more precise.
Veni, vidi, abiit domum
|
|
|
|
|
|
Page 18 of the manual describes a technique by which you can manipulate the value of port 0x4B8 by using the debug.exe program while running under DOS or Win98.
Assuming the (cash) register has it's own OS and that I/O ports are accessible to user programs, you can simply use the inp/outp functions as found in <conio.h> .
Using the first example given in table 4.2.3, I've extended the table by 1 column to include the equivalent C code.
Command | Cash Drawer 1 | C code
-----------------------------------------------------------
O 4B8 01 | Opening | outp(0x4B8, 0x01);
O 4B8 00 | Allow to closing | outp(0x4B8, 0x00);
Looking at the second table, one can see that a read of the port is required along with bit-masking to get at the desired bit.
1. Read the value.
2. Mask the unwanted bits.
3. Check the value remaining.
unsigned int curStatus = inp(0x4B8);
curStatus = curStatus & 0x10; if (curStatus == 0)
printf("Drawer is open\n"); else
printf("Drawer is closed\n");
|
|
|
|
|
Unfortunately I can't use the inp function. I am running winXP on my machine. According to this : "If you are using a 32-bit compiler on either MS-Windows or *nix then forget those two functions because they are not implemented by any 32-bit/64-bit compiler. The operating system will not permit direct access to hardware or computer ports. You have to use normal operating system api functions. Those two functions were written for 16-bit MS-DOS which did permit programs direct access to hardware." I can't use theese functions.
|
|
|
|
|
I'd wondered if I was going to get a response something like that after seeing mention of XP in the manual you linked to.
In that case, you'll have to communicate with the drawer via a device-driver. They operate in ring0 under XP, and have direct access to the hardware - much like every program did under DOS.
There should be accompanying documentation of the steps required to interface to such a driver from a user-land program. (ring2 in XP).
If there is no driver, you'll need to write one yourself. Which, I'm led to believe isn't necessarily as difficult as it may sound. You can download the WDK from microsoft (not the SDK) and go through some of the examples in it to get a start.
Here's a very brief write-up regarding the different privilege levels in XP: http://www.craigberntson.com/blog/?p=789[^]
And another that explains the concept of privilege levels in general: http://en.wikipedia.org/wiki/Ring_(computer_security)[^]
|
|
|
|
|
First of all thanks for your reply. I'll give it a try but i think that is too advanced for me. I've read the article about priviledge levels in XP so I understood what the problem was.Now I'm downloading the WDK.
|
|
|
|
|
You're welcome. Driver development isn't exactly an easy topic to broach, though you're bound to find some examples around the net of "Hello World" type examples. There may even be some here at CP, I haven't looked.
You wouldn't need terribly much functionality in the driver, so you may well find it considerably easier than it seems daunting. You could probably start with just two functions above the basic house-keeping stuff. One to read the value of the register(port) and another to write a value to it. You could then provide finer functionality in a user-mode DLL for specifics like opening the drawer etc - i.e use the ability to write a register from the DLL, setting the appropriate bit.
Best of luck, hope it works out well for you.
|
|
|
|
|
Hi, I'm noob in programming language and I need to make some project using it. So I tried to make a game called 'Baghchal'/Tiger and Goat/Moving Tiger, but its too complex for me so I copied Sir Srinivas Varukala's code. When I run compile the program it shows error about 'cannot include mouse.h file'. I would be glad to receive any kind of idea or help. Here is the source code
Tiger Goat Console Based Game - using C++[^]
|
|
|
|
|
You should post your question in the forum at the end of the article so the author gets notified.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks Richard, I couldn't think of that earlier. Thanks again
|
|
|
|
|
OS interrupts are only used in 16-bit MSDOS apps. More [here ]
You can try this code for a WIN32 console app.
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE hIn;
HANDLE hOut;
COORD KeyWhere;
COORD MouseWhere;
COORD EndWhere;
bool Continue = TRUE;
int KeyEvents = 0;
int MouseEvents = 0;
INPUT_RECORD InRec;
DWORD NumRead;
hIn = GetStdHandle(STD_INPUT_HANDLE);
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "Key Events : " << endl;
cout << "Mouse Events : " << flush;
KeyWhere.X = 15;
KeyWhere.Y = 0;
MouseWhere.X = 15;
MouseWhere.Y = 1;
EndWhere.X = 0;
EndWhere.Y = 3;
while (Continue)
{
ReadConsoleInput(hIn,
&InRec,
1,
&NumRead);
switch (InRec.EventType)
{
case KEY_EVENT:
++KeyEvents;
SetConsoleCursorPosition(hOut,
KeyWhere);
cout << KeyEvents << flush;
if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
{
SetConsoleCursorPosition(hOut,
EndWhere);
cout << "Exiting..." << endl;
Continue = FALSE;
}
break;
case MOUSE_EVENT:
++MouseEvents;
SetConsoleCursorPosition(hOut,
MouseWhere);
cout << MouseEvents << flush;
break;
}
}
return 0;
}
More : [here ]
|
|
|
|
|
Is this the header file?
I need mouse.h for turbo c++. Thanks for the code.
|
|
|
|
|
Turbo C++ code.
Copy paste this to a file named mouse.h .
<-------- start of mouse.h
include <fstream.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <alloc.h>
const ress=0xb;
unsigned hspd,vspd,thv,button,mouse_x,mouse_y;
int dirx,diry,dir_x,dir_y,trshold;
unsigned char mousestep;
void initmouse(void)
{
asm{
mov ax,1h
int 33h
}
}
void hidemouse(void)
{
asm{
mov ax,2h
int 33h
}
}
void getmousepos(void)
{
asm{
mov ax,3h
int 33h
mov button,bx
mov mouse_x,cx
mov mouse_y,dx
}
}
void getmousedirection(void)
{
asm{
mov ax,ress
int 33h
mov trshold,bx
mov dirx,cx
mov diry,dx
}
}
void getmousespeed(void)
{
asm{
mov ax,1bh
int 33h
mov bx,hspd
mov cx,vspd
mov dx,thv
}
}
<-------- end of mouse.h
|
|
|
|
|
Thanks, I think it works, error relating to mouse.h is gone but not all so I will reply as soon as I debug it.
|
|
|
|
|
Hi, SuperCoder2014 your codes and links solve the problem about mouse handling during runtime but I stuck at deleting the bar3d(). At some point I have to create bar3d() using <graphics.h> and after pressing mouse button I have to make disapper that bar3d() on the same background. Thanks for your help before, and I would appreciate any reply.
|
|
|
|
|
I don't think this message was meant for me.
Veni, vidi, abiit domum
|
|
|
|
|
Yes, RICHARD it wasn't, it was for SUPERCODER2014. And as u said I posted on author's forum too, I think that might help
|
|
|
|
|
And my message was not directed at you, but SuperCoder2014.
Veni, vidi, abiit domum
|
|
|
|
|
Ohh, sorry my bad, u know that I posted the problem, right? I changed name from number to myth1990.
Sorry for misunderstanding
|
|
|
|