Search code examples
c#apiokuma

Call I/O status from the API on Okuma Lathes


I am working on a testing program for checking the Barfeeder interface on Okuma machines. I will need to check status of certain inputs and output. I am a little confused on the GetBitIO Method. I am wanting to check the status of for example the iIN24 input at 0104 bit 7.

Code:

 private CIO IO;

 IO = new CIO();

 private void button1_Click(object sender, EventArgs e)
 {
 string IOin24 = IO.GetBitIO(Input, 0104, 7).ToString();
 }

The above line test the "Input" with an error that the name doesn't exist in the current context.

 private CIO IO;

 IO = new CIO();

 private void button1_Click(object sender, EventArgs e)
 {
 string IOin24 = IO.GetBitIO(104, 7, 0).ToString();
 }

Try a minor change to the line of this.

 string IOin24 = IO.GetBitIO(0, 7, 104).ToString();

The above line gets an error for whole command from the api. Error states that the it cannot convert from int to Okuma.CLDATAPI.Enumerations.BitsEnum. This line is similar to how I got data for VB.Net without issues.

VB code used before to get the NC reset push button (ipNCRT) at address 0 bit 2.

 Private Sub RadioButton4_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RadioButton4.Checked
 TextBox2.Text = IO.GetBitIO(0, 2, 0).ToString
 End Sub

Reading the help for the API for Lathes I get the following rules.

Parameters:

[C#] public OnOffStateEnum GetBitIO(IOTypeEnum enIO, int intAddressIndex, BitsEnum enBits);

enIO I/O variable type. Values of parameter come from Okuma.CLDATAPI.Enumerations.IOTypeEnum enumeration.

ntAddressIndex Logical I/O address index

enBits Bit number. Values of parameter come from Okuma.CLDATAPI.Enumerations.BitsEnum enumeration.


Solution

  • The basic problem is that you compiled the VB program with Option Strict turned off and it allowed you to pass raw integers into a function that expected to take an Enum.

    I don't have a manual for your specific library from the machine manufacturer, but the general idea will be something like :

    string IOin24 = IO.GetBitIO(IOTypeEnum.Input, 0104, BitsEnum.Bit4).ToString();
    

    I've just made up the names for the enum members but if you read through the documentation you got with your software (or maybe even just type in IOTypeEnum. and see if IntelliSense gives you a list) to find out what the corresponding strongly typed members are for the integers you are trying to pass.

    You will need to make sure, also, that you have included the assembly in question - ie :

    using Okuma.CLDATAPI.Enumerations;
    

    should appear at the top of your class file somewhere.