using Manufactor snippets (Convert C programs to Gambas)

Post

Posted
Rating:
#1 (In Topic #1216)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi Everyone

I was wondering if someone could advise me

a Supplier of my PoS Terminal has given me a few programs they have made in C to get the status of the cash drawer port as well as Open the drawer
I also have libptcash.so and libptcash.a files and the read me is telling me to use that from my user program (but I have no clue how to do that)
but they are small single run program

does anyone know how they could be converted to Gambas so i could monitor the cash drawer port all the time (i have attached the C source code so if someone smarter then me wants to see it they can)

My machine a 2 (PT621X_A)

Code (gambas)

  1. //MACHINE_TYPE
  2. #define PT6200_A 1
  3. #define PT621X_A 2
  4. #define PT5700_A 3
  5. #define PT571X_A 4
  6. #define PT6900_A 5
  7. #define PT691X_A 6
  8. #define PT8800_A 7
  9. //\{==add by frankie on 20111027
  10. #define PT8850_A 8
  11. #define SP800_A 9
  12. #define SP1000_A 10
  13. #define SP820_A 11
  14. #define  PT6315C_A 11
  15.  
  16.  
  17. #define SP600_A 12
  18. #define SP810_A 13
  19. #define WT_110_A 14
  20. #define SP2500_A  15
  21. #define SP3515_A  15
  22.  
  23. #define SP1060_A  16
  24. #define SP7615_A  17
  25. #define SP7615_A_IO  19
  26. #define SP5615_A  18
  27. //==}
  28. #define PT6200_B 21
  29. #define PT621X_B 22
  30. #define PT5700_B 23
  31. #define PT571X_B 24
  32. #define PT6900_B 25
  33. #define PT691X_B 26
  34. #define PT8800_B 27
  35. //\{==add by frankie on 20111027
  36. #define PT8850_B 28
  37. #define SP800_B  29
  38. #define SP1000_B 30
  39. #define SP820_B  31
  40. #define  PT6315C_B 31
  41.  
  42. #define SP600_B  32
  43. #define SP810_B  33
  44. #define WT_110_B 34
  45.  
  46. #define SP2500_B  35
  47. #define SP3515_B  35
  48.  
  49. #define SP1060_B  36
  50. #define SP7615_B  37
  51. #define SP5615_B  38
  52. //==}
  53. /********************************************************************
  54. Function: Open_Cash(int machine_type)
  55. Description:
  56.                   Open the cash drawer.
  57. Parameter:
  58.                   int machine_type : should be one of
  59.                           PT6200 , PT621X , PT5700 , PT571X , PT6900 , PT691X,PT8800
  60.                           return val:
  61.                 0: open success
  62.                 1: open fail
  63.  
  64. ********************************************************************/
  65. // 0: success  -1: fail
  66. int Open_Cash(int machine_type);
  67.  
  68.  
  69. /********************************************************************
  70. Function: Get_Cash_Status(int machine_type)
  71. Description:
  72.                   Open the cash drawer.
  73. Parameter:
  74.                   int machine_type : should be one of
  75.                           PT6200 , PT621X , PT5700 , PT571X , PT6900 , PT691X ,PT8800
  76.                           return val:
  77.                 0: cash drawer closed
  78.                 1: cash drawer opened
  79.  
  80. ********************************************************************/
  81. int Get_Cash_Status(int machine_type);
  82.  
  83. /********************************************************************
  84. Function: ReadSN(unsigned char * psnbuf)
  85. Description:
  86.                   read the MB Serial Number.
  87. Parameter:
  88.         psnbuf,will return the SN, 12 characters
  89.                 0: success
  90.                 -1: fail
  91.  
  92. ********************************************************************/
  93. int ReadSN(unsigned char * psnbuf);
  94.  

Code (gambas)

  1. #include <stdio.h>
  2. #include "cashdrawer.h"
  3.  
  4. int main(int argc,char *argv[])
  5. \{     
  6.         int machine_type;
  7.         int ret;
  8.  
  9.         machine_type = atoi(argv[1]);
  10.         ret=Open_Cash(machine_type);
  11.         printf("open cash return = %d\n",ret);
  12.         if(ret == 0)
  13.                 printf("open success\n");
  14.         else
  15.                 printf("open fail\n");
  16. }
  17.  

Code (gambas)

  1. #include <stdio.h>
  2. #include "cashdrawer.h"
  3.  
  4. int main(int argc,char *argv[])
  5. \{
  6.         int machine_type;      
  7.         int status;
  8.  
  9.         machine_type =  atoi(argv[1]);
  10.         status=Get_Cash_Status(machine_type);
  11.         printf("get cash status = %2x\n",status);
  12.         if(status == 1)
  13.                 printf("cash drawer is opened\n");
  14.         else if(status == 0)
  15.                 printf("cash drawer is closed\n");
  16.         else
  17.                 printf("get cash status fail\n");
  18. }
  19.  

Ideally I would like to be able to click on the Gambas App a button that says "Open Drawer" and it will open the drawer and then show a mesage saying "Please close the drawer" until they close the Drawer


Below is the readme file (and it talks about threaded API)

Code (gambas)

  1. 1. How to install the Partner cashdrawer driver
  2.         1) tar -xvzf PT_Cashdrawer_Driver.tar.gz
  3.         2) cd  PT_Cashdrawer_Driver
  4.         3)  
  5.                 sh install.sh
  6.          ( the install.sh need using the "root" user permission)
  7.         4) reboot
  8. 2. How to test the driver
  9.         1) cd PT_Cashdrawer_Driver/test_utilities/64bit (if your linux is 32bit ,so please into the folder "32bit")
  10.         2) ./opencash xx (will open the cashdrawer,xx is the machine type. The machine type please check the cashdrawer.h .For example: ./opencash 11  , will open SP820_A)
  11.         3) ./getstatus xx(will get the cashdrawer open/close status)
  12.         4) ./readSN  (will return the mainboard's Serial Number)
  13. 3. How to uninstall the driver
  14.         sh uninstall.sh
  15.                
  16. 4.How to call the open/stastus API in usr program
  17.  
  18.         We provide two dll :libptcash.so ,libptcashc++.so . Default please using the libptcash.so ,if your program is using the C++,maybe using the libptcash.so will have problem.So please using the libptcahsc++.so.
  19.  
  20. 5.Thredd APIs be provided:
  21.  
  22.         1)int Open_Cash(int machine_type); Open the cash drawer.
  23.         2)int Get_Cash_Status(int machine_type); Get the cash drawer open/close status.
  24.         3)int ReadSN(unsigned char * psnbuf); Get the mainboard's Serial Number.
  25.        
  26.         the description like these:
  27.  
  28. /********************************************************************
  29. Function: Open_Cash(int machine_type)
  30. Description:
  31.                   Open the cash drawer.
  32. Parameter:
  33.                   int machine_type : should be one of
  34.                           PT6200 , PT621X , PT5700 , PT571X , PT6900 , PT691X, PT8800........
  35.                           return val:
  36.                 0: open success
  37.                 1: open fail
  38.  
  39. ********************************************************************/
  40. int Open_Cash(int machine_type);
  41.  
  42.  
  43. /********************************************************************
  44. Function: Get_Cash_Status(int machine_type)
  45. Description:
  46.                   Open the cash drawer.
  47. Parameter:
  48.                   int machine_type : should be one of
  49.                           PT6200 , PT621X , PT5700 , PT571X , PT6900 , PT691X, PT8800........
  50.                           return val:
  51.                 0: cash drawer closed
  52.                 1: cash drawer opened
  53.  
  54. ********************************************************************/
  55. int Get_Cash_Status(int machine_type);
  56.  
  57. /********************************************************************
  58. Function: ReadSN(unsigned char * psnbuf)
  59. Description:
  60.                   read the MB Serial Number.
  61. Parameter:
  62.         psnbuf,will return the SN, 12 characters
  63.                 0: success
  64.                 -1: fail
  65.  
  66. ********************************************************************/
  67. int ReadSN(unsigned char * psnbuf);
  68.  
  69.  
  70. 5.About the "machine_type"
  71. #define PT6200_A 1
  72. #define PT621X_A 2
  73. #define PT5700_A 3
  74. #define PT571X_A 4
  75. #define PT6900_A 5
  76. #define PT691X_A 6
  77. #define PT8800_A 7
  78. #define PT8850_A 8
  79. #define SP800_A 9
  80. #define SP1000_A 10
  81. #define SP820_A 11
  82. #define PT6315C_A 11
  83. #define SP600_A 12
  84. #define SP810_A 13
  85. #define WT_110_A 14
  86. #define SP2500_A  15
  87. #define SP3515_A  15
  88. #define SP5514_A  15
  89. #define SP1060_A  16
  90. #define SP2600_A  16
  91. #define SP7615_A  17
  92. #define SP5615_A  18
  93.  
  94. #define PT6200_B 21
  95. #define PT621X_B 22
  96. #define PT5700_B 23
  97. #define PT571X_B 24
  98. #define PT6900_B 25
  99. #define PT691X_B 26
  100. #define PT8800_B 27
  101. #define PT8850_B 28
  102. #define SP800_B  29
  103. #define SP1000_B 30
  104. #define SP820_B  31
  105. #define PT6315C_B 31
  106. #define SP600_B  32
  107. #define SP810_B  33
  108. #define WT_110_B 34
  109. #define SP2500_B  35
  110. #define SP3515_B  35
  111. #define SP5514_B  35
  112. #define SP1060_B  36
  113. #define SP2600_B  36
  114. #define SP7615_B  37
  115. #define SP5615_B  38
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
Uhmmmm….

C CODE:

#include <stdio.h>
#include "cashdrawer.h"
 
int main(int argc,char *argv[])
{   
    int machine_type;
    int ret;
 
    machine_type = atoi(argv[1]);
        ret=Open_Cash(machine_type);
    printf("open cash return = %d\n",ret);
    if(ret == 0)
        printf("open success\n");
    else
        printf("open fail\n");
}

- - - - - - - - - - - - - - - - - - - - - -

GAMBAS CODE:

Code (gambas)

  1. Library "/path/of/libptcash"
  2.  
  3. Private Const PT6200_A As Integer = 1
  4. Private Const PT621X_A As Integer = 2
  5. Private Const PT5700_A As Integer = 3
  6. etc....
  7. etc....
  8.  
  9. ' int Open_Cash(int machine_type)
  10. ' Open the cash drawer.
  11. Private Extern Open_Cash(machine_type As Integer) As Integer
  12.  
  13.  
  14. Public Sub Form_Open()
  15.  
  16.   Dim machine_type, ret As Integer
  17.  
  18.   machine_type = Val(InputBox("Insert machine-type code..."))
  19.  
  20.   ret = Open_Cash(machine_type)
  21.  
  22.   Print "open cash return = "; ret
  23.   If ret == 0 Then
  24.     Print "open success"
  25.   Else
  26.     Print "open fail"
  27.   Endif
  28.  


==========================================================

C CODE:

#include <stdio.h>
#include "cashdrawer.h"
 
int main(int argc,char *argv[])
{
    int machine_type;   
    int status;
 
    machine_type =  atoi(argv[1]);
    status=Get_Cash_Status(machine_type);
    printf("get cash status = %2x\n",status);
    if(status == 1)
        printf("cash drawer is opened\n");
    else if(status == 0)
        printf("cash drawer is closed\n");
    else
        printf("get cash status fail\n");
}

- - - - - - - - - - - - - - - - - - - - - -


GAMBAS CODE:

Code (gambas)

  1. Library "/path/of/libptcash"
  2.  
  3. Private Const PT6200_A As Integer = 1
  4. Private Const PT621X_A As Integer = 2
  5. Private Const PT5700_A As Integer = 3
  6. etc....
  7. etc....
  8.  
  9. ' int Get_Cash_Status(int machine_type)
  10. ' Get the cash drawer open/close status.
  11. Private Extern Get_Cash_Status(machine_type As Integer) As Integer
  12.  
  13.  
  14. Public Sub Form_Open()
  15.  
  16.   Dim machine_type, status As Integer
  17.  
  18.   machine_type = Val(InputBox("Insert machine_type code..."))
  19.  
  20.   status = Get_Cash_Status(machine_type)
  21.  
  22.   Print "get cash status = "; status
  23.   If status == 1 Then
  24.     Print "cash drawer is opened"
  25.   Else If status == 0
  26.     Print "cash drawer is closed"
  27.   Else
  28.     Print "get cash status fail"
  29.   Endif
  30.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

vuott said

Uhmmmm….

C CODE:

#include <stdio.h>
#include "cashdrawer.h"
 
int main(int argc,char *argv[])
{   
    int machine_type;
    int ret;
 
    machine_type = atoi(argv[1]);
        ret=Open_Cash(machine_type);
    printf("open cash return = %d\n",ret);
    if(ret == 0)
        printf("open success\n");
    else
        printf("open fail\n");
}

- - - - - - - - - - - - - - - - - - - - - -

GAMBAS CODE:

Code (gambas)

  1. Library "/path/of/libptcash"
  2.  
  3. Private Const PT6200_A As Integer = 1
  4. Private Const PT621X_A As Integer = 2
  5. Private Const PT5700_A As Integer = 3
  6. etc....
  7. etc....
  8.  
  9. ' int Open_Cash(int machine_type)
  10. ' Open the cash drawer.
  11. Private Extern Open_Cash(machine_type As Integer) As Integer
  12.  
  13.  
  14. Public Sub Form_Open()
  15.  
  16.   Dim machine_type, ret As Integer
  17.  
  18.   machine_type = InputBox("Insert machine-type code...")
  19.  
  20.   ret = Open_Cash(machine_type)
  21.  
  22.   Print "open cash return = "; ret
  23.   If ret == 0 Then
  24.     Print "open success"
  25.   Else
  26.     Print "open fail"
  27.   Endif
  28.  


==========================================================

C CODE:

#include <stdio.h>
#include "cashdrawer.h"
 
int main(int argc,char *argv[])
{
    int machine_type;   
    int status;
 
    machine_type =  atoi(argv[1]);
    status=Get_Cash_Status(machine_type);
    printf("get cash status = %2x\n",status);
    if(status == 1)
        printf("cash drawer is opened\n");
    else if(status == 0)
        printf("cash drawer is closed\n");
    else
        printf("get cash status fail\n");
}

- - - - - - - - - - - - - - - - - - - - - -


GAMBAS CODE:

Code (gambas)

  1. Library "/path/of/libptcash"
  2.  
  3. Private Const PT6200_A As Integer = 1
  4. Private Const PT621X_A As Integer = 2
  5. Private Const PT5700_A As Integer = 3
  6. etc....
  7. etc....
  8.  
  9. ' int Get_Cash_Status(int machine_type)
  10. ' Get the cash drawer open/close status.
  11. Private Extern Get_Cash_Status(machine_type As Integer) As Integer
  12.  
  13.  
  14. Public Sub Form_Open()
  15.  
  16.   Dim machine_type, status As Integer
  17.  
  18.   machine_type = InputBox("Insert machine_type code...")
  19.  
  20.   status = Get_Cash_Status(machine_type)
  21.  
  22.   Print "get cash status = "; status
  23.   If status == 1 Then
  24.     Print "cash drawer is opened"
  25.   Else If status == 0
  26.     Print "cash drawer is closed"
  27.   Else
  28.     Print "get cash status fail"
  29.   Endif
  30.  


Thank you so much I shall give them a go over the next few days
Online now: No Back to the top
1 guest and 0 members have just viewed this.