Arduino -> ModBus -> LCNC

Обсуждение установки, настройки и использования LinuxCNC. Вопросы по Gкоду.
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

в прошивке конфигурируется и в самом скрипте тоже...
поэтому - чтоб удобно и полноценно можно было ковырять всегда под свои нужды -
поставить емс из исходников и редактировать с компиляцией как только заблагорассудится)))
поставленая из исходников емсни коим образом не помеха той,что установлена в систему ...
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

подскажите что я делаю не так
Пытаюсь установить новый компонент скачанный в этой теме Arduino -> ModBus -> LCNC #53
предварительно с папки удаляю старый компонент и ложу туда файл gs2_vfd.c
в терминале получаю так

Код: Выделить всё

cnc@cnc-desktop:~$ cd /usr/bin
cnc@cnc-desktop:/usr/bin$ make
make: *** Не заданы цели и не найден make-файл.  Останов.
cnc@cnc-desktop:/usr/bin$ make gs2_vfd
cc     gs2_vfd.c   -o gs2_vfd
gs2_vfd.c:10:19: error: rtapi.h: Нет такого файла или каталога
gs2_vfd.c:11:17: error: hal.h: Нет такого файла или каталога
gs2_vfd.c:12:20: error: modbus.h: Нет такого файла или каталога
gs2_vfd.c:30: error: expected specifier-qualifier-list before ‘hal_s32_t’
gs2_vfd.c:110: error: expected ‘)’ before ‘*’ token
gs2_vfd.c:132: error: expected ‘)’ before ‘*’ token
gs2_vfd.c: In function ‘main’:
gs2_vfd.c:179: error: ‘modbus_param_t’ undeclared (first use in this function)
gs2_vfd.c:179: error: (Each undeclared identifier is reported only once
gs2_vfd.c:179: error: for each function it appears in.)
gs2_vfd.c:179: error: expected ‘;’ before ‘mb_param’
gs2_vfd.c:235: error: ‘HAL_NAME_LEN’ undeclared (first use in this function)
gs2_vfd.c:294: error: ‘mb_param’ undeclared (first use in this function)
gs2_vfd.c:323: error: ‘HAL_OUT’ undeclared (first use in this function)
gs2_vfd.c:323: error: ‘haldata_t’ has no member named ‘Ain0’
gs2_vfd.c:325: error: ‘haldata_t’ has no member named ‘Ain1’
gs2_vfd.c:327: error: ‘haldata_t’ has no member named ‘Ain2’
gs2_vfd.c:329: error: ‘haldata_t’ has no member named ‘Ain3’
gs2_vfd.c:331: error: ‘haldata_t’ has no member named ‘Ain4’
gs2_vfd.c:333: error: ‘haldata_t’ has no member named ‘Ain5’
gs2_vfd.c:335: error: ‘haldata_t’ has no member named ‘Ain6’
gs2_vfd.c:337: error: ‘haldata_t’ has no member named ‘Ain7’
gs2_vfd.c:339: error: ‘haldata_t’ has no member named ‘Ain8’
gs2_vfd.c:341: error: ‘haldata_t’ has no member named ‘Ain9’
gs2_vfd.c:343: error: ‘haldata_t’ has no member named ‘Ain10’
gs2_vfd.c:345: error: ‘haldata_t’ has no member named ‘Ain11’
gs2_vfd.c:347: error: ‘haldata_t’ has no member named ‘Ain12’
gs2_vfd.c:349: error: ‘haldata_t’ has no member named ‘Ain13’
gs2_vfd.c:351: error: ‘haldata_t’ has no member named ‘Ain14’
gs2_vfd.c:353: error: ‘haldata_t’ has no member named ‘Ain15’
gs2_vfd.c:356: error: ‘HAL_IN’ undeclared (first use in this function)
gs2_vfd.c:356: error: ‘haldata_t’ has no member named ‘pwm1’
gs2_vfd.c:358: error: ‘haldata_t’ has no member named ‘pwm2’
gs2_vfd.c:360: error: ‘haldata_t’ has no member named ‘pwm3’
gs2_vfd.c:362: error: ‘haldata_t’ has no member named ‘pwm4’
gs2_vfd.c:364: error: ‘haldata_t’ has no member named ‘pwm5’
gs2_vfd.c:366: error: ‘haldata_t’ has no member named ‘pwm6’
gs2_vfd.c:369: error: ‘haldata_t’ has no member named ‘Dout1’
gs2_vfd.c:371: error: ‘haldata_t’ has no member named ‘Dout2’
gs2_vfd.c:373: error: ‘haldata_t’ has no member named ‘Dout3’
gs2_vfd.c:375: error: ‘haldata_t’ has no member named ‘Dout4’
gs2_vfd.c:377: error: ‘haldata_t’ has no member named ‘Dout8’
gs2_vfd.c:379: error: ‘haldata_t’ has no member named ‘Dout9’
gs2_vfd.c:381: error: ‘haldata_t’ has no member named ‘Dout12’
gs2_vfd.c:385: error: ‘haldata_t’ has no member named ‘Ain0’
gs2_vfd.c:386: error: ‘haldata_t’ has no member named ‘Ain1’
gs2_vfd.c:387: error: ‘haldata_t’ has no member named ‘Ain2’
gs2_vfd.c:388: error: ‘haldata_t’ has no member named ‘Ain3’
gs2_vfd.c:389: error: ‘haldata_t’ has no member named ‘Ain4’
gs2_vfd.c:390: error: ‘haldata_t’ has no member named ‘Ain5’
gs2_vfd.c:391: error: ‘haldata_t’ has no member named ‘Ain6’
gs2_vfd.c:392: error: ‘haldata_t’ has no member named ‘Ain7’
gs2_vfd.c:393: error: ‘haldata_t’ has no member named ‘Ain8’
gs2_vfd.c:394: error: ‘haldata_t’ has no member named ‘Ain9’
gs2_vfd.c:395: error: ‘haldata_t’ has no member named ‘Ain10’
gs2_vfd.c:396: error: ‘haldata_t’ has no member named ‘Ain11’
gs2_vfd.c:397: error: ‘haldata_t’ has no member named ‘Ain12’
gs2_vfd.c:398: error: ‘haldata_t’ has no member named ‘Ain13’
gs2_vfd.c:399: error: ‘haldata_t’ has no member named ‘Ain14’
gs2_vfd.c:400: error: ‘haldata_t’ has no member named ‘Ain15’
gs2_vfd.c:402: error: ‘haldata_t’ has no member named ‘Dout1’
gs2_vfd.c:403: error: ‘haldata_t’ has no member named ‘Dout2’
gs2_vfd.c:404: error: ‘haldata_t’ has no member named ‘Dout3’
gs2_vfd.c:405: error: ‘haldata_t’ has no member named ‘Dout4’
gs2_vfd.c:406: error: ‘haldata_t’ has no member named ‘Dout8’
gs2_vfd.c:407: error: ‘haldata_t’ has no member named ‘Dout9’
gs2_vfd.c:408: error: ‘haldata_t’ has no member named ‘Dout12’
gs2_vfd.c:415: error: ‘haldata_t’ has no member named ‘looptime’
gs2_vfd.c:415: error: ‘haldata_t’ has no member named ‘looptime’
gs2_vfd.c:416: error: ‘haldata_t’ has no member named ‘looptime’
gs2_vfd.c:416: error: ‘haldata_t’ has no member named ‘looptime’
gs2_vfd.c:417: error: ‘haldata_t’ has no member named ‘looptime’
gs2_vfd.c:418: error: ‘haldata_t’ has no member named ‘looptime’
make: *** [gs2_vfd] Ошибка 1
cnc@cnc-desktop:/usr/bin$ 

nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

solo писал(а):Ага заработала конфигурация........ в Lcnc видна ардуина в ней куча пинов
так уже вроде бы работало??
==========
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

я пробую установить другой компонент и посмотреть может там есть такие пины в ардуине как мне нужны
Мне надо входных 16 выход 20 и 6 ШИМ , Может уже что то готовое есть в теме
Просто в данный момент у меня Lcnc стоит на ноутбуке который подключен к интернету на котором я тренируюсь и экспериментирую если все получается перенесу на станок, компр на станке без инета и на нем не очень удобно тренироваться.
Последний раз редактировалось solo 19 фев 2014, 18:09, всего редактировалось 1 раз.
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

solo писал(а):Мне надо входных 16 выход 20 и 6 ШИМ
не ищи - сделаем...
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

16_din , 20_dout , 16_ain , 6_pwm
скетч:

Код: Выделить всё

/*
     Modbus Slave designed for Mach 3 CNC Software
 Written by: Tim W. Shilling, March 4, 2012.
 Released into the Public Domain 
 */
//############################################
//  Supportted Functions
//  1:  Read Coil
//  2:  Read Descrete Input   
//  3:  Read Holding Reg
//  4:  Read Input Reg
//  5:  Write Single Coil
//  6:  Write Single Reg
//  7   Read Exception
//  15: Write Multiple Coils
//  16: Write Multiple Holding Reg

// Notes on Timing:
// Original Design implemented Timer 1 and 0, but these conflict with the PWM generators
// Timers dropped for millis and micros functions.  Not as accurate but fine for this purpose

//################# INCLUDES #################
#include <Modbus_Slave.h>    // Ensure you have included the libraries in the Arduino Libraries folder

//################# DEFINES ##################
#define Baudrate 19200       //Desired Baud Rate, Recommend, 9600, 19200, 56800, 115200
#define Freq 16000000        //Don't Touch unless using a differnt board, Freq of Processor
#define Slave_Address 0x01   //Address of MODBus Slave
#define Kill_Time 2000       //2 Sec (2000msec) keep alive, 0 => OFF

//############  REGISTER DEFINES ############# // Each Register is 16bit
#define Digital_IO_Register 0
#define PWM_Register        10
#define AN_Register         30
#define Timer_Register      50
#define IO_Config_Register  60
#define Kill_IO_Register    70
#define PWMIOMap_Register   80
#define ANIOMap_Register    81
#define General_Config      90
#define Error_Register      91
#define Digital_IO_Pins     53   //Total number of Digital IO pins, Limits update scanner pin count
#define Number_Of_Registers 100
//############ GLOBAL VARIABLES ##############
unsigned char Data[256];                                         // All received data ends up in here, also used as output buffer 
unsigned short Index = 0;                                        // Current Location in Data
unsigned short Register[Number_Of_Registers];                    // Where all user data, Coils/Registers are kept
ModBusSlave ModBus(Slave_Address,Register,Number_Of_Registers);  // Initialize a new ModBus Slave, Again, you must have my Arduino ModBusSlave Library 
unsigned long Last_Time=0;
unsigned long Time = 0;
unsigned long LongBreakTime;                                            //Time for 3.5 characters to be RX
//################## Setup ###################
// Takes:   Nothing
// Returns: Nothing
// Effect:  Opens Serial port 1 at defined Baudrate
//          Configures all Pins
//          Initiallized Timer 1
void setup()
{
  //################ Initialize IO #################     // 0 => Output, 1 => Input, opposite of normal Arduino, but my habit from other platforms, 0 looks like an O and 1 looks like an I
  Register[IO_Config_Register]    = 0b0000000000000000;  // UNO and MEGA  PIN 00-15
  Register[IO_Config_Register+1]  = 0b1111111111111111;  // MEGA          PIN 16-31
  Register[IO_Config_Register+2]  = 0b0000000000000000;  // MEGA          PIN 32-47
  Register[IO_Config_Register+3]  = 0b0000000000000000;  // MEGA          PIN 48-64
  Register[IO_Config_Register+4]  = 0b1111111111111111;  // AN Digital    PIN A0-A16

  //################ Kill IO Register #################  // 0 => Leave, 1 => Kill
  Register[Kill_IO_Register]    = 0b1111111111111111;    // UNO and MEGA  PIN 00-15
  Register[Kill_IO_Register+1]  = 0b1111111111111111;    // MEGA          PIN 16-31
  Register[Kill_IO_Register+2]  = 0b1111111111111111;    // MEGA          PIN 32-47
  Register[Kill_IO_Register+3]  = 0b1111111111111111;    // MEGA          PIN 48-64
  Register[Kill_IO_Register+4]  = 0b1111111111111111;    // AN Digital    PIN A0-A16

  //################ PWM IO Register #################   // 0 => Normal I/O, 1 => PWM I/O
  Register[PWMIOMap_Register]   = 0b0000111001101000;    // UNO and MEGA  PWM 01-16

  //################ AN IO Register #################    // 0 => Digital, 1=> Analog
  Register[ANIOMap_Register]    = 0b1111111111111111;    // UNO and MEGA

  Config_IO();

  LongBreakTime = (long)((long)28000000.0/(long)Baudrate);
  if(Baudrate > 19200)
    LongBreakTime = 1750;                                // 1.75 msec
  Serial.begin(Baudrate);                                // Open Serial port at Defined Baudrate
  Time = micros();                                       // Preload Time variable with current System microsec
}

//################ Main Loop #################
// Takes:   Nothing
// Returns: Nothing
// Effect:  Main Program Loop

unsigned long LongKillTime = (long)((long)Kill_Time * (long)1000);      //Time ellapsed between RX that causes system Kill

unsigned long Keep_Alive = 0;                                           // Keep Alive Counter Variable

void loop()
{
  Update_Time();
  if(Keep_Alive >= LongKillTime){               // Communications not Received in Kill_Time, Execute Lost Comm Emerency Procedure
    if(Kill_Time != 0){                         // If Kill_Time is 0, then disable Lost Comm Check
      Keep_Alive = LongKillTime;                // Avoid Keep_Alive rollover
      ModBus.Error = 0xff;                      // Set error code to Lost Comm
      Register[Error_Register] = ModBus.Error;  // Set Error Register
      Kill_IO();                                // Kill what should be killed
      digitalWrite(13,1);                       // Indicate Error with Solid LED
    }
  }
  else
  {
    Update_Pin_States();                        // Update Digital Pins
    Update_AN_States();                         // Update Analog Pins
    if(ModBus.Error != 0){                      // Flash Error LED is ModBus Error != 0
      digitalWrite(13,bitRead(Time,11));        // Toggle LED
    }
    else                                        // If no Error
    {
      digitalWrite(13,0);                       // Turn off LED
    }
  }
  //######################## RX Data ###############################
  if (Serial.available() > 0)                   // If Data Avilable
  {
    Data[Index] = (unsigned char)Serial.read(); // Read Next Char 
    Keep_Alive = 0;                             // Reset Keep Alive counter     
    Last_Time = micros();                       // Update Last_Time to current Time
    Index++;                                    // Move Index Counter Forward
  }
  //##################### Process Data #############################
  if(Index > 0)                                 // If there are bytes to be read
  {
    if(Keep_Alive >= LongBreakTime)             // Transmission Complete, 3.5 char spacing observered
    {
      Register[Timer_Register] = (unsigned int)(millis() / 125.0);  // Converts to 1/8sec and load into Register 
      ModBus.Process_Data(Data,Index);          // Process Data
      if(ModBus.Error == 0)                     // If no Errors, then... 
      {
        Keep_Alive = 0;                         // Reset Keep Alive 
        Last_Time = micros();                   // Set Last_Time to current time
      }
      else                                      // If there was an error
      {
        Register[Error_Register] = ModBus.Error;// Set Error Code
      }
      Index = 0;                                // Reset Index to 0, no bytes to read
    }
  }
}
//################ Update Time #################
// Takes:   Nothing
// Returns: Nothing
// Effect:  Updates Timer Register
//          Updates KeepAlive Count

void Update_Time()
{
  Last_Time = Time;                             // Set Last_Time to Current Time
  Time = micros();
  if(Time < Last_Time)                          // Counter has rolled over, should take 70 Min
  {
    Last_Time = 0;                              // Introduces a small clitch in timing by not accounting for how bad the roll over was.  Happens every 70 Min
                                                // Result is Delta will be smaller than it should be, Kill and Character Spacing will be usec longer than they should  
  }
  Keep_Alive += Time - Last_Time;               // Increment Keep Alive counter
  Register[Timer_Register] = (unsigned int)(millis() / 125.0);  // Converts to 1/8sec and load into Register 
}
//EOF

скрипт:

Код: Выделить всё

/*
PINS_PWM
3 5 6 9 10 11 

PINS_IN
16 - 31

PINS_OUT
32 - 47
48 49 50 51 52
*/
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <getopt.h>
#include "rtapi.h"
#include "hal.h"
#include "modbus.h"

#define START_REGISTER_R	0x1E
#define NUM_REGISTERS_R		16
#define START_REGISTER_W	0
#define NUM_REGISTERS_W		3
#undef DEBUG

typedef struct {
	int slave;		
	int read_reg_start;	
	int read_reg_count;	
	int write_reg_start;	
	int write_reg_count;	
} slavedata_t;

typedef struct {
  hal_s32_t retval;
  hal_float_t looptime; 
   
  hal_s32_t *pwm03;
  hal_s32_t *pwm05;
  hal_s32_t *pwm06;
  hal_s32_t *pwm09;
  hal_s32_t *pwm10;
  hal_s32_t *pwm11;  
  
  hal_bit_t *Din10;
  hal_bit_t *Din11;
  hal_bit_t *Din12;
  hal_bit_t *Din13;
  hal_bit_t *Din14;
  hal_bit_t *Din15;
  hal_bit_t *Din16;
  hal_bit_t *Din17;
  hal_bit_t *Din18;
  hal_bit_t *Din19;
  hal_bit_t *Din110;
  hal_bit_t *Din111;
  hal_bit_t *Din112;
  hal_bit_t *Din113;
  hal_bit_t *Din114;
  hal_bit_t *Din115;  
  
  hal_bit_t *Dout20;
  hal_bit_t *Dout21;
  hal_bit_t *Dout22;
  hal_bit_t *Dout23;
  hal_bit_t *Dout24;
  hal_bit_t *Dout25;
  hal_bit_t *Dout26;
  hal_bit_t *Dout27;
  hal_bit_t *Dout28;
  hal_bit_t *Dout29;
  hal_bit_t *Dout210;
  hal_bit_t *Dout211;
  hal_bit_t *Dout212;
  hal_bit_t *Dout213;
  hal_bit_t *Dout214;
  hal_bit_t *Dout215;
 
  hal_bit_t *Dout30;
  hal_bit_t *Dout31;
  hal_bit_t *Dout32;
  hal_bit_t *Dout33;
  hal_bit_t *Dout34; 
     
  hal_s32_t *Ain40;
  hal_s32_t *Ain41;
  hal_s32_t *Ain42;
  hal_s32_t *Ain43;
  hal_s32_t *Ain44;
  hal_s32_t *Ain45;
  hal_s32_t *Ain46;
  hal_s32_t *Ain47;
  hal_s32_t *Ain48;
  hal_s32_t *Ain49;
  hal_s32_t *Ain410;
  hal_s32_t *Ain411;
  hal_s32_t *Ain412;
  hal_s32_t *Ain413;
  hal_s32_t *Ain414;
  hal_s32_t *Ain415;
} haldata_t;
static int done;
char *modname = "arduino";
static struct option long_options[] = {
    {"bits", 1, 0, 'b'},
    {"device", 1, 0, 'd'},
    {"debug", 0, 0, 'g'},
    {"help", 0, 0, 'h'},
    {"name", 1, 0, 'n'},
    {"parity", 1, 0, 'p'},
    {"rate", 1, 0, 'r'},
    {"stopbits", 1, 0, 's'},
    {"target", 1, 0, 't'},
    {"verbose", 0, 0, 'v'},
    {0,0,0,0}
};
static char *option_string = "b:d:hn:p:r:s:t:v";
static char *bitstrings[] = {"5", "6", "7", "8", NULL};
static char *paritystrings[] = {"even", "odd", "none", NULL};
static char *ratestrings[] = {"110", "300", "600", "1200", "2400", "4800", "9600",
    "19200", "38400", "57600", "115200", NULL};
static char *stopstrings[] = {"1", "2", NULL};

static void quit(int sig) {
    done = 1;
}
int match_string(char *string, char **matches) {
    int len, which, match;
    which=0;
    match=-1;
    if ((matches==NULL) || (string==NULL)) return -1;
    len = strlen(string);
    while (matches[which] != NULL) {
        if ((!strncmp(string, matches[which], len)) && (len <= strlen(matches[which]))) {
            if (match>=0) return -1;        // multiple matches
            match=which;
        }
        ++which;
    }
    return match;
}
void usage(int argc, char **argv) {
    printf("Usage:  %s [options]\n", argv[0]);
    printf(
    "This is a userspace HAL program, typically loaded using the halcmd \"loadusr\" command:\n"
    "    loadusr gs2_vfd\n"
    "There are several command-line options.  Options that have a set list of possible values may\n"
    "    be set by using any number of characters that are unique.  For example, --rate 5 will use\n"
    "    a baud rate of 57600, since no other available baud rates start with \"5\"\n"
    "-b or --bits <n> (default 8)\n"
    "    Set number of data bits to <n>, where n must be from 5 to 8 inclusive\n"
    "-d or --device <path> (default /dev/ttyS0)\n"
    "    Set the name of the serial device node to use\n"
    "-g or --debug\n"
    "    Turn on debugging messages.  This will also set the verbose flag.  Debug mode will cause\n"
    "    all modbus messages to be printed in hex on the terminal.\n"
    "-n or --name <string> (default gs2_vfd)\n"
    "    Set the name of the HAL module.  The HAL comp name will be set to <string>, and all pin\n"
    "    and parameter names will begin with <string>.\n"
    "-p or --parity {even,odd,none} (defalt odd)\n"
    "    Set serial parity to even, odd, or none.\n"
    "-r or --rate <n> (default 38400)\n"
    "    Set baud rate to <n>.  It is an error if the rate is not one of the following:\n"
    "    110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200\n"
    "-s or --stopbits {1,2} (default 1)\n"
    "    Set serial stop bits to 1 or 2\n"
    "-t or --target <n> (default 1)\n"
    "    Set MODBUS target (slave) number.  This must match the device number you set on the GS2.\n"
    "-v or --verbose\n"
    "    Turn on debug messages.  Note that if there are serial errors, this may become annoying.\n"
    "    At the moment, it doesn't make much difference most of the time.\n");
}
int write_data(modbus_param_t *param, slavedata_t *slavedata, haldata_t *haldata) {  //==============  write  ====================
     int retval ;
     int  v2 ,v3;
     //шим (пины:3,5,6,9,10,11)
     preset_single_register(param, 1, 13, abs((int)(*(haldata->pwm03))));   //(Reg:13,15,16,19,20,21)
     preset_single_register(param, 1, 15, abs((int)(*(haldata->pwm05))));   
     preset_single_register(param, 1, 16, abs((int)(*(haldata->pwm06))));
     preset_single_register(param, 1, 19, abs((int)(*(haldata->pwm09))));
     preset_single_register(param, 1, 20, abs((int)(*(haldata->pwm10))));
     preset_single_register(param, 1, 21, abs((int)(*(haldata->pwm11))));
     
    
     v2 = (*(haldata->Dout20))      | (*(haldata->Dout21))<<1   | (*(haldata->Dout22))<<2   | (*(haldata->Dout23))<<3   | 
          (*(haldata->Dout24))<<4   | (*(haldata->Dout25))<<5   | (*(haldata->Dout26))<<6   | (*(haldata->Dout27))<<7   | 
          (*(haldata->Dout28))<<8   | (*(haldata->Dout29))<<9   | (*(haldata->Dout210))<<10 | (*(haldata->Dout211))<<11 | 
          (*(haldata->Dout212))<<12 | (*(haldata->Dout213))<<13 | (*(haldata->Dout214))<<14 | (*(haldata->Dout215))<<15 ;
     retval = preset_single_register(param, 1, 2, v2); //посылаем в устройство1, регистр 0 число v2

     v3 = (*(haldata->Dout30)) | (*(haldata->Dout31))<<1 | (*(haldata->Dout32))<<2 | (*(haldata->Dout33)<<3) | (*(haldata->Dout34))<<4 ;
     retval = preset_single_register(param, 1, 3, v3); //посылаем в устройство1, регистр 3 число v3
     
    return retval;
}
int read_data(modbus_param_t *param, slavedata_t *slavedata, haldata_t *hal_data_block) {
    int receive_data[MAX_READ_HOLD_REGS];	
    int retval;
    int Reg1val=0;
    int mass1[16];
    int x = 0;

    if (hal_data_block == NULL)
        return -1;
    if ((param==NULL) || (slavedata == NULL)) {  
        return -1;
    }  
    //---------------------------------------читаем  цифровые входы --------регистр1
        retval = read_holding_registers(param, slavedata->slave, 1 , 1 , receive_data);         
        if (retval==1) {
        retval = 0;
        hal_data_block->retval = retval;
        if (retval==0) {
        Reg1val  = receive_data[0] ;
        x = 0;
        while ( x < 16  ){
		if ((Reg1val & 0x01) == 1 ) 
			mass1[x] = 1;
		else
			mass1[x] = 0;
		Reg1val=Reg1val>>1;
		x++; 
		}
	*(hal_data_block->Din10)   = mass1[0];		
	*(hal_data_block->Din11)   = mass1[1];		
	*(hal_data_block->Din12)   = mass1[2];
	*(hal_data_block->Din13)   = mass1[3];
	*(hal_data_block->Din14)   = mass1[4];
	*(hal_data_block->Din15)   = mass1[5];
	*(hal_data_block->Din16)   = mass1[6];
	*(hal_data_block->Din17)   = mass1[7];
	*(hal_data_block->Din18)   = mass1[8];
	*(hal_data_block->Din19)   = mass1[9];
	*(hal_data_block->Din110)  = mass1[10];
	*(hal_data_block->Din111)  = mass1[11];
	*(hal_data_block->Din112)  = mass1[12];
	*(hal_data_block->Din113)  = mass1[13];
	*(hal_data_block->Din114)  = mass1[14];
	*(hal_data_block->Din115)  = mass1[15];                                         
        retval = 0;
        }
    }
    else {
        hal_data_block->retval = retval;
        retval = -1;
    }    
    //----------------------------------------------------читаем  аналоговые входы --------регистр4
    retval = read_holding_registers(param, slavedata->slave, slavedata->read_reg_start,
                                slavedata->read_reg_count, receive_data);    
    if (retval==slavedata->read_reg_count) {
        retval = 0;
        hal_data_block->retval = retval;
        if (retval==0) {
        *(hal_data_block->Ain40)  = receive_data[0] ;
        *(hal_data_block->Ain41)  = receive_data[1] ;
        *(hal_data_block->Ain42)  = receive_data[2] ;
        *(hal_data_block->Ain43)  = receive_data[3] ;        
        *(hal_data_block->Ain44)  = receive_data[4] ;
        *(hal_data_block->Ain45)  = receive_data[5] ;
        *(hal_data_block->Ain46)  = receive_data[6] ;
        *(hal_data_block->Ain47)  = receive_data[7] ;
        *(hal_data_block->Ain48)  = receive_data[8] ;
        *(hal_data_block->Ain49)  = receive_data[9] ;
        *(hal_data_block->Ain410) = receive_data[10];
        *(hal_data_block->Ain411) = receive_data[11];
        *(hal_data_block->Ain412) = receive_data[12];
        *(hal_data_block->Ain413) = receive_data[13];
        *(hal_data_block->Ain414) = receive_data[14];
        *(hal_data_block->Ain415) = receive_data[15];        
        retval = 0;
        }
    } else {
        hal_data_block->retval = retval;
  
        retval = -1;
    }
//========================================                                                           
    return retval;
}
int main(int argc, char **argv)
{
    int retval;
    modbus_param_t mb_param;
    haldata_t *haldata;
    slavedata_t slavedata;
    int hal_comp_id;
    struct timespec loop_timespec, remaining;
    int baud, bits, stopbits, debug, verbose;
    char *device, *parity, *endarg;
    int opt;
    int argindex, argvalue;
    
    done = 0;
    baud = 19200;
    bits = 8;
    stopbits = 1;
    debug = 0;
    verbose = 0;
    device = "/dev/ttyACM0";
    parity = "none";

    slavedata.slave = 1;
    slavedata.read_reg_start = START_REGISTER_R;
    slavedata.read_reg_count = NUM_REGISTERS_R;
    slavedata.write_reg_start = START_REGISTER_W;
    slavedata.write_reg_count = NUM_REGISTERS_R;
    
        // process command line options
    while ((opt=getopt_long(argc, argv, option_string, long_options, NULL)) != -1) {
        switch(opt) {
            case 'b':   // serial data bits, probably should be 8 (and defaults to 8)
                argindex=match_string(optarg, bitstrings);
                if (argindex<0) {
                
                    printf("gs2_vfd: ERROR: invalid number of bits: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                bits = atoi(bitstrings[argindex]);
                break;
            case 'd':   // device name, default /dev/ttyS0
                // could check the device name here, but we'll leave it to the library open
                if (strlen(optarg) > FILENAME_MAX) {
                    printf("gs2_vfd: ERROR: device node name is too long: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                device = strdup(optarg);
                break;
            case 'g':
                debug = 1;
                verbose = 1;
                break;
            case 'n':   // module base name
                if (strlen(optarg) > HAL_NAME_LEN-20) {
                    printf("gs2_vfd: ERROR: HAL module name too long: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                modname = strdup(optarg);
                break;
            case 'p':   // parity, should be a string like "even", "odd", or "none"
                argindex=match_string(optarg, paritystrings);
                if (argindex<0) {
                    printf("gs2_vfd: ERROR: invalid parity: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                parity = paritystrings[argindex];
                break;
            case 'r':   // Baud rate, 38400 default
                argindex=match_string(optarg, ratestrings);
                if (argindex<0) {
                    printf("gs2_vfd: ERROR: invalid baud rate: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                baud = atoi(ratestrings[argindex]);
                break;
            case 's':   // stop bits, defaults to 1
                argindex=match_string(optarg, stopstrings);
                if (argindex<0) {
                    printf("gs2_vfd: ERROR: invalid number of stop bits: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                stopbits = atoi(stopstrings[argindex]);
                break;
            case 't':   // target number (MODBUS ID), default 1
                argvalue = strtol(optarg, &endarg, 10);
                if ((*endarg != '\0') || (argvalue < 1) || (argvalue > 254)) {
                    printf("gs2_vfd: ERROR: invalid slave number: %s\n", optarg);
                    retval = -1;
                    goto out_noclose;
                }
                slavedata.slave = argvalue;
                break;
            case 'v':   // verbose mode (print modbus errors and other information), default 0
                verbose = 1;
                break;
            case 'h':
            default:
                usage(argc, argv);
                exit(0);
                break;
        }
    }
    printf("%s: device='%s', baud=%d, bits=%d, parity='%s', stopbits=%d, address=%d, verbose=%d\n",
           modname, device, baud, bits, parity, stopbits, slavedata.slave, debug);
    /* point TERM and INT signals at our quit function */
    /* if a signal is received between here and the main loop, it should prevent
            some initialization from happening */
    signal(SIGINT, quit);
    signal(SIGTERM, quit);
    
    modbus_init_rtu(&mb_param, device, baud, parity, bits, stopbits, verbose);

    mb_param.debug = debug;
    if (((retval = modbus_connect(&mb_param))!=0) || done) {
        printf("%s: ERROR: couldn't open serial device\n", modname);
        goto out_noclose;
    }

    hal_comp_id = hal_init(modname);
    if ((hal_comp_id < 0) || done) {
        printf("%s: ERROR: hal_init failed\n", modname);
        retval = hal_comp_id;
        goto out_close;
    }
    haldata = (haldata_t *)hal_malloc(sizeof(haldata_t));
    if ((haldata == 0) || done) {
        printf("%s: ERROR: unable to allocate shared memory\n", modname);
        retval = -1;
        goto out_close;
    }
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm03), hal_comp_id, "%s.pwm03", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm05), hal_comp_id, "%s.pwm05", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm06), hal_comp_id, "%s.pwm06", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm09), hal_comp_id, "%s.pwm09", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm10), hal_comp_id, "%s.pwm10", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_IN, &(haldata->pwm11), hal_comp_id, "%s.pwm11", modname); if (retval!=0) goto out_closeHAL;  
    
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din10),    hal_comp_id, "%s.Din1-16" , modname); if (retval!=0) goto out_closeHAL;   
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din11),    hal_comp_id, "%s.Din1-17" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din12),    hal_comp_id, "%s.Din1-18" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din13),    hal_comp_id, "%s.Din1-19" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din14),    hal_comp_id, "%s.Din1-20" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din15),    hal_comp_id, "%s.Din1-21" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din16),    hal_comp_id, "%s.Din1-22" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din17),    hal_comp_id, "%s.Din1-23" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din18),    hal_comp_id, "%s.Din1-24" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din19),    hal_comp_id, "%s.Din1-25" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din110),   hal_comp_id, "%s.Din1-26", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din111),   hal_comp_id, "%s.Din1-27", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din112),   hal_comp_id, "%s.Din1-28", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din113),   hal_comp_id, "%s.Din1-29", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din114),   hal_comp_id, "%s.Din1-30", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_OUT, &(haldata->Din115),   hal_comp_id, "%s.Din1-31", modname); if (retval!=0) goto out_closeHAL;

    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout20),    hal_comp_id, "%s.Dout2-32" , modname); if (retval!=0) goto out_closeHAL;   
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout21),    hal_comp_id, "%s.Dout2-33" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout22),    hal_comp_id, "%s.Dout2-34" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout23),    hal_comp_id, "%s.Dout2-35" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout24),    hal_comp_id, "%s.Dout2-36" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout25),    hal_comp_id, "%s.Dout2-37" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout26),    hal_comp_id, "%s.Dout2-38" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout27),    hal_comp_id, "%s.Dout2-39" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout28),    hal_comp_id, "%s.Dout2-40" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout29),    hal_comp_id, "%s.Dout2-41" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout210),   hal_comp_id, "%s.Dout2-42", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout211),   hal_comp_id, "%s.Dout2-43", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout212),   hal_comp_id, "%s.Dout2-44", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout213),   hal_comp_id, "%s.Dout2-45", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout214),   hal_comp_id, "%s.Dout2-46", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout215),   hal_comp_id, "%s.Dout2-47", modname); if (retval!=0) goto out_closeHAL;

    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout30),    hal_comp_id, "%s.Dout3-48" , modname); if (retval!=0) goto out_closeHAL;    
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout31),    hal_comp_id, "%s.Dout3-49" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout32),    hal_comp_id, "%s.Dout3-50" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout33),    hal_comp_id, "%s.Dout3-51" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_bit_newf(HAL_IN, &(haldata->Dout34),    hal_comp_id, "%s.Dout3-52" , modname); if (retval!=0) goto out_closeHAL;
    
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain40),    hal_comp_id, "%s.Ain4-00" , modname); if (retval!=0) goto out_closeHAL;   
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain41),    hal_comp_id, "%s.Ain4-01" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain42),    hal_comp_id, "%s.Ain4-02" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain43),    hal_comp_id, "%s.Ain4-03" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain44),    hal_comp_id, "%s.Ain4-04" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain45),    hal_comp_id, "%s.Ain4-05" , modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain46),    hal_comp_id, "%s.Ain4-06" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain47),    hal_comp_id, "%s.Ain4-07" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain48),    hal_comp_id, "%s.Ain4-08" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain49),    hal_comp_id, "%s.Ain4-09" , modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain410),   hal_comp_id, "%s.Ain4-10", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain411),   hal_comp_id, "%s.Ain4-11", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain412),   hal_comp_id, "%s.Ain4-12", modname); if (retval!=0) goto out_closeHAL; 
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain413),   hal_comp_id, "%s.Ain4-13", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain414),   hal_comp_id, "%s.Ain4-14", modname); if (retval!=0) goto out_closeHAL;
    retval = hal_pin_s32_newf(HAL_OUT, &(haldata->Ain415),   hal_comp_id, "%s.Ain4-15", modname); if (retval!=0) goto out_closeHAL;       
 
    *(haldata->Din10)  = 0;    
    *(haldata->Din11)  = 0; 
    *(haldata->Din12)  = 0;
    *(haldata->Din13)  = 0;
    *(haldata->Din14)  = 0;
    *(haldata->Din15)  = 0;
    *(haldata->Din16)  = 0;
    *(haldata->Din17)  = 0;
    *(haldata->Din18)  = 0;
    *(haldata->Din19)  = 0;
    *(haldata->Din110) = 0;
    *(haldata->Din111) = 0;
    *(haldata->Din112) = 0;
    *(haldata->Din113) = 0;
    *(haldata->Din114) = 0;
    *(haldata->Din115) = 0;
  
    *(haldata->Dout20)  = 0;    
    *(haldata->Dout21)  = 0; 
    *(haldata->Dout22)  = 0;
    *(haldata->Dout23)  = 0;
    *(haldata->Dout24)  = 0;
    *(haldata->Dout25)  = 0;
    *(haldata->Dout26)  = 0;
    *(haldata->Dout27)  = 0;
    *(haldata->Dout28)  = 0;
    *(haldata->Dout29)  = 0;
    *(haldata->Dout210) = 0;
    *(haldata->Dout211) = 0;
    *(haldata->Dout212) = 0;
    *(haldata->Dout213) = 0;
    *(haldata->Dout214) = 0;
    *(haldata->Dout215) = 0;

    *(haldata->Dout30) = 0;    
    *(haldata->Dout31) = 0; 
    *(haldata->Dout32) = 0;
    *(haldata->Dout33) = 0;
    *(haldata->Dout34) = 0;
    
    *(haldata->Ain40)  = 0;    
    *(haldata->Ain41)  = 0; 
    *(haldata->Ain42)  = 0;
    *(haldata->Ain43)  = 0;
    *(haldata->Ain44)  = 0;
    *(haldata->Ain45)  = 0;
    *(haldata->Ain46)  = 0;
    *(haldata->Ain47)  = 0;
    *(haldata->Ain48)  = 0;
    *(haldata->Ain49)  = 0;
    *(haldata->Ain410) = 0;
    *(haldata->Ain411) = 0;
    *(haldata->Ain412) = 0;
    *(haldata->Ain413) = 0;
    *(haldata->Ain414) = 0;
    *(haldata->Ain415) = 0;

    while (done==0) {
        read_data(&mb_param, &slavedata, haldata);
        write_data(&mb_param, &slavedata, haldata);
        if (haldata->looptime < 0.001) haldata->looptime = 0.001;
        if (haldata->looptime > 2.0) haldata->looptime = 2.0;
        loop_timespec.tv_sec = (time_t)(haldata->looptime);
        loop_timespec.tv_nsec = (long)((haldata->looptime - loop_timespec.tv_sec) * 1000000000l);
        nanosleep(&loop_timespec, &remaining);
    }    
    retval = 0;
out_closeHAL:
    hal_exit(hal_comp_id);
out_close:
    modbus_close(&mb_param);
out_noclose:
    return retval;
}
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

solo писал(а):Мне надо входных 16 выход 20 и 6 ШИМ
этим файлом из архива :
gs2_vfd.rar
(22.79 КБ) 412 скачиваний
заменяем одноименный в системе( /usr/bin )
==========
всё работает - проверил входы-выходы и шим...
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение Nick »

nkp писал(а):тут такое дело:
мы изменяем компонент gs2_vfd.c,
А почему бы не сделать другой компонент, или просто дать ему новое имя и устанавливать его потом через comp install.... (тогда для этого понадобится только linuxcnc-dev )...
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

Nick писал(а):А почему бы не сделать другой компонент, или просто дать ему новое имя и устанавливать его потом через comp install.... (тогда для этого понадобится только linuxcnc-dev )...
через comp не получится, надо makefile поправить
а я пока в этом не очень :monkey: :)
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение Nick »

Это не просто компонент? Там что-то еще есть?
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

Nick писал(а):Это не просто компонент? Там что-то еще есть?
я могу ошибаться - но мне кажеться comp только для компонентов реалтайм...

Код: Выделить всё

Compile .comp and .c files into HAL userspace components (the --compile --userspace flag)
==========
тогда конечно надо попробовать ;)
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

попробовал - ошибка :

Код: Выделить всё

nkp@nkp-desktop:~$ sudo comp --install --userspace ard_mod.c
gcc -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/realtime-2.6.32-122-rtai/include -D_FORTIFY_SOURCE=0 -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime -D__MODULE__ -I/usr/include/linuxcnc -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Os  -o ard_mod /tmp/tmpcHaR9O/ard_mod.c -Wl,-rpath,/lib -L/lib -llinuxcnchal 
/tmp/tmpcHaR9O/ard_mod.c:167: error: expected ‘)’ before ‘*’ token
/tmp/tmpcHaR9O/ard_mod.c:190: error: expected ‘)’ before ‘*’ token
/tmp/tmpcHaR9O/ard_mod.c: In function ‘main’:
/tmp/tmpcHaR9O/ard_mod.c:274: error: ‘modbus_param_t’ undeclared (first use in this function)
/tmp/tmpcHaR9O/ard_mod.c:274: error: (Each undeclared identifier is reported only once
/tmp/tmpcHaR9O/ard_mod.c:274: error: for each function it appears in.)
/tmp/tmpcHaR9O/ard_mod.c:274: error: expected ‘;’ before ‘mb_param’
/tmp/tmpcHaR9O/ard_mod.c:387: error: ‘mb_param’ undeclared (first use in this function)
make: *** [ard_mod] Ошибка 1
nkp@nkp-desktop:~$
первое впечатление - что comp парсит в темпфайл исходник как то по своему
а скорей дело в библиотеках - ложить наверно рядом...(а там потянется столько)))
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

оплять чего то не так,
моя чайниковатость прогресирует.
Не пихается у меня скетч в арбуино
Чего то под убунтой не могу скопировать ошибку компиляции
вставлю фото экрана с ошибкой



запихнул в ардуино скетч с это темы но не помню в каком сообщении по этому прикреплю его здесь еще раз
с этим скечем и новым компонентом вроде Lcnc запускается появились пины нужные
, буду дальше тестировать
Вложения
Arduino.rar
скетч который работает сейчас
(9.13 КБ) 379 скачиваний
ошибка скетча с сообщения http://cnc-club.ru/forum/posting.php?mode=reply&amp;f=41&amp;t=3803#pr109148 (2259 просмотров) <a class='original' href='./download/file.php?id=25073&mode=view' target=_blank>Загрузить оригинал (60.89 КБ)</a>
ошибка скетча с сообщения http://cnc-club.ru/forum/posting.php?mode=reply&f=41&t=3803#pr109148
Последний раз редактировалось solo 20 фев 2014, 14:41, всего редактировалось 1 раз.
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

у меня вот так выглядит окно при загрузке прошивки:
Выделение_038.png (2257 просмотров) <a class='original' href='./download/file.php?id=25075&mode=view' target=_blank>Загрузить оригинал (125.2 КБ)</a>
но я так понял - все уже наладилось...
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

А можно скетч в виде файла а не кодом
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

чтоб ардуина правильно открывала файлы прошивок - нужно чтоб сами скетчи лежали в папке с таким же именем...
Рабочий стол 1_041.png (2254 просмотра) <a class='original' href='./download/file.php?id=25079&mode=view' target=_blank>Загрузить оригинал (129.01 КБ)</a>
у меня к примеру папка для скетчей /home/nkp/Arduino
Выделение_042.png (2254 просмотра) <a class='original' href='./download/file.php?id=25077&mode=view' target=_blank>Загрузить оригинал (31.44 КБ)</a>
в /home/nkp/Arduino/ModBusSlave как раз нужные нам скетчи
Выделение_043.png (2254 просмотра) <a class='original' href='./download/file.php?id=25078&mode=view' target=_blank>Загрузить оригинал (14.19 КБ)</a>
solo писал(а):А можно скетч в виде файла а не кодом
ModBusSlave.rar
(4.48 КБ) 383 скачивания
а здесь нужно настроить путь к папке со скетчами:
Выделение_044.png (2254 просмотра) <a class='original' href='./download/file.php?id=25081&mode=view' target=_blank>Загрузить оригинал (94.46 КБ)</a>
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

О теперь все прошилось без ошибок
Я чего то туплю ШИМ пин здесь называется arduino.pwm 03 так он вроде IN
тогда наверное это arduino.Ain-00 а номирация пинов програмная и физическая на плате МЕГА 2560 совпадают с А0 или с D22 или как.
Вложения
Снимок-1.png (2250 просмотров) <a class='original' href='./download/file.php?id=25085&mode=view' target=_blank>Загрузить оригинал (361.11 КБ)</a>
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

нумерацию пинов сделал соответственно Mega
solo писал(а): ШИМ пин здесь называется arduino.pwm 03 так он вроде IN
тут все правильно - для хал - это будет IN - вход
ты же будешь в хал подавать на этот пин какое либо значение (с какого нибудь выходного пина OUT,и этот пин должен быть S32)
=========
кстати - может повторюсь - на шим пин нужно подавать значения от нуля до 254
ноль - на ножке будет 0V
254 - на ножке будет 5V(реально у меня ~4,8V)
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение nkp »

solo писал(а):arduino.Ain-00
а это аналоговые входы - ты не заказывал - но я оставил - чего же ногам пропадать))))
Аватара пользователя
solo
Мастер
Сообщения: 1374
Зарегистрирован: 20 окт 2011, 18:39
Репутация: 272
Настоящее имя: Юрий Соловьев
Откуда: Украина Харьков
Контактная информация:

Re: Arduino -> ModBus -> LCNC

Сообщение solo »

О спасибо
сейчас буду предметно и детально разбираться нарисую панельку и буду экспериментировать.
с меня причитается :beer: :beer: :beer:
Ответить

Вернуться в «LinuxCNC»