I have a VB.net app that I use to communicate with a Fanuc CNC controller with a PC front end using the Fanuc Focas Libraries. The Fanuc CNC controller controls the operation of a machine tool that is used to cut metal parts. The Focas libraries has a series of different functions I can call to read/write different variables from the Fanuc CNC.
We just recently purchased another Fanuc CNC controller. The existing controller we were using is no longer available so we had to upgrade to a newer version. Over the last few days, I have been testing my app on the new controller to make sure everything works properly. Most everything works fine but I have found a few functions that do not work. Below you will find the function and the structure that doesn't work:
Public Const MAX_AXIS = 8
Declare Function cnc_absolute Lib "FWLIB32.DLL" _
(ByVal FlibHndl As Integer, ByVal a As Short, ByVal b As Short, ByRef c As ODBAXIS) As Short
<StructLayout(LayoutKind.Sequential,Pack:=4)> _
Public Structure ODBAXIS
Public dummy As Short ' dummy
Public type As Short ' axis number
<MarshalAs(UnmanagedType.ByValArray,SizeConst:=MAX_AXIS)> _
Public data As Integer() ' data value
End Structure 'ODBAXIS
Private Sub rd_abs_pos()
Dim nLen, i As Short
Dim nValid_fig As Integer
Dim nDec_fig_in(Focas1.MAX_AXIS) As Short
Dim nDec_fig_out(Focas1.MAX_AXIS) As Short
Dim dTmp As Double
Dim ax_abs As Focas1.ODBAXIS
nLen = 4 + (4 * Focas1.MAX_AXIS)
nRet = Focas1.cnc_setpath(FlibHndl, 1)
ErrPath.Text = nRet.ToString
nRet = Focas1.cnc_absolute(FlibHndl, Focas1.ALL_AXES, nLen, ax_abs)
ErrRet.Text = CStr(nRet)
nRet = Focas1.cnc_getfigure(FlibHndl, Focas1.AXIS_DATA, nValid_fig, nDec_fig_in, nDec_fig_out)
ErrRet.Text = CStr(nRet)
dTmp = CDbl(ax_abs.data(i))
dTmp = dTmp / (10 ^ nDec_fig_in(i))
Select Case i
Case 0
XPos.Text = dTmp.ToString("0.0000")
Case 1
Case 2
YPos.Text = dTmp.ToString("0.0000")
Case 3
ZPos.Text = dTmp.ToString("0.0000")
End Select
Next i
End Sub
After doing some investigating, i found out that this new controller has the capability to control more machine axis's compared to the old controller. Instead of 8, the new controller can control 32. After I changed the MAX_AXIS constant from 8 to 32, everything worked fine.
My current app runs on multiple machines with the old controller. The app is currently deployed via click once. Over the next few months, we plan to deploy multiple machines with the new controller. For simplicity sake, I was hoping I could run the same app on both controllers. I was planning on adding a new setting to my apps config file so I could modify the way the app runs depending on which controller it had. To make this work, I was going to change MAX_AXIS to a integer variable vs a const and set it to 8 for the old controller and then 32 for the new controller. When I made this change, I got an error in my structure saying that a constant expression is required. I'm not 100% sure why I'm getting this error but my guess is VB.net needs to know the exact size before it compiles.
I've read online that I could fix this issue by using the #IF statement to set this constant before compiling. If I do this, I am going to have to deploy 2 different apps. Then when I publish my app, I am going to have to make sure I publish the correct version to the correct deployment folder. Is there any other option I can use to make this work using the same executable?