Converting string to byte to be send over RS485

Hello,
I try to write a code to programm my trinamic stepper-motor driver. The card has an RS485 interface.
I connected my arduino via a RS485 PCB and got it working physical.
After some coding I got this program working (The motor turns right and stops after 2 seconds):

#include <SoftwareSerial.h>    // just in case I have to use a MEGA
#define TX_ENABLE_PIN 4           // define the EIA-485 transmit driver pin ( RE + DE pin's modules)

SoftwareSerial rs485(2, 3);    // SoftwareSerial rs485(RO, DI)

// commands to be send
// rotate right 0A 02 00 00 00 00 30 D4 10
// motor stop 0A 03 00 00 00 00 00 00 0D

byte rot_r [] = {
  0x0A,  // address
  0x02,  // Command
  0x00,  // type
  0x00,  // motor #
  0x00,  // val0
  0x00,  // val1
  0x30,  // val2
  0xD4,  // val3
  0x10   // checksum
};
byte mstop [] = {
  0x0A,  // address
  0x03,  // Command
  0x00,  // type
  0x00,  // motor #
  0x00,  // val0
  0x00,  // val1
  0x00,  // val2
  0x00,  // val3
  0x0D   // checksum
};

void setup() {
  pinMode(TX_ENABLE_PIN, OUTPUT);  // driver output enable
  rs485.begin (57600);              
  Serial.begin(57600);
  Serial.println("SETUP DONE\n");
}

void loop() {
  // rotate right  
  digitalWrite (TX_ENABLE_PIN, HIGH);     // enable transmit driver
  for (int i = 0; i < 9; i++) {
     rs485.write(rot_r[i]);                // rotate right
  }
  digitalWrite(TX_ENABLE_PIN, LOW);       // disable transmit driver
  delay(2000);

  // stop motor
  digitalWrite (TX_ENABLE_PIN, HIGH);     // enable transmit driver
  for (int i = 0; i < 9; i++) {
     rs485.write(mstop[i]);                // stop motor
  }
  digitalWrite(TX_ENABLE_PIN, LOW);       // disable transmit driver
  delay(2000);
}

As I want the commands to be in an array which should be filled with content, read from an SD-Card, I need a function to convert from string to byte.

After aditional research through the internet I found a function which converts String to byte. I enhanced my code as followed

#include <SoftwareSerial.h>
#define TX_ENABLE_PIN 4           // define the EIA-485 transmit driver pin
SoftwareSerial rs485(2, 3);       // SoftwareSerial rs485(RO, DI); pins name on the module
// rotate right 0A 02 00 00 00 00 30 D4 10
// motor stop 0A 03 00 00 00 00 00 00 0D

char command[18] = {"0A020000000030D410"}; // rotate right

byte stringToByte(char *src, int numBytes)
{
  char charBuffer[18];
  int charToInt;
  byte intToByte;
  Serial.print("BUFFER ");
  Serial.println(charBuffer);
  memcpy(charBuffer, src, numBytes);
  charToInt = atoi(charBuffer);
  Serial.print("INT ");
  Serial.println(charToInt);
  intToByte = (byte)charToInt;
  return intToByte;
}

void setup() {
  pinMode(TX_ENABLE_PIN, OUTPUT);  // driver output enable
  rs485.begin (57600);              
  Serial.begin(57600);
  Serial.println("INIT DONE\n");
  digitalWrite (TX_ENABLE_PIN, HIGH); 
  rs485.write("\n\r RS485-INIT-DONE\n\r"); // 485 Alive ?!
  digitalWrite (TX_ENABLE_PIN, LOW); 
  Serial.println(stringToByte(command,18));
}

void loop() {
  digitalWrite (TX_ENABLE_PIN, HIGH);     // enable transmit driver
  rs485.write(stringToByte(command,18));
  digitalWrite(TX_ENABLE_PIN, LOW);       // disable transmit driver
  delay(2000);
}

but with no success.Only 0 or $ arrive in my controlling "minicom-RS485-linux-pc". Could someone please help me, convert my string(s) to byte?
Thanks

A c string (character array) is already an array of bytes. Do you want to convert an ASCII representation of a byte (in your example maybe a hexadecimal representation of bytes) into a byte stream?

The above line can be written in the following manner; where, each character/digit has been replaced by the corresponding ASCII code.

char command[] = {0x30, 0x41, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x30, 0x44, 0x34, 0x31, 0x30, 0x00};

Or using C syntax:
char command[] = {'0', 'A', '0', '2', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', 'D', '4', '1', '0', '\0'}; 

Thanks so far, I'm confused in which way to convert, I can only say that the stepper controller reacts to data send as in the first code example (byte).
I'd like to use ASCII-Data, as they should be read from an SD-card to be converted to byte?stream???
The data in the string command are already hex-representation.

For example (just a fast hack, not tested):

uint8_t hex_digit(char in) {
  if (in <= '9') {
    return in - '0';
  } else {
    return in - 'A';
  }
}

void decode_hexstring(char *src, uint8_t *dest) {
  for (uint16_t i = 0; i < strlen(src); i+=2) {
    dest[i>>1] = hex_digit(src[i]) << 4 | hex_digit(src[i+1]);
  }
}

looks like you really want to transmit an message that is an array of bytes. you could translate each nibble (4 bits into an ascii char (0-9a-f). presumably the benefit is you would send the message as an ASCII string with a conventional termination character which is easily recognizable using something like readBytesUntil().

of course this approach sends twice as many bytes as actual data. the message could be sent as binary bytes, but you then need someway to delineate at least the start of the message with some sequence of bytes that recognizable and not likely to be message data, such as 0xff 0xff 0xff, 0xff

There are many ways to do what I think you want. Here's an approach which converts the sequential two char hex nibbles into numerical values using strtol() in base 16. To use this function, the two character nibbles need to temporarily in a null terminated array. The values need to come from the SD card with leading zeros as you have indicated in your posting.

void setup() {
  //9 byte command plus null = 19 bytes
  char command[19] = {"0A020000000030D410"}; // rotate right
  byte numBytes = (sizeof(command) - 1) / 2; //one byte per 2 hex chars need sizeof() for constant array bound
  byte byteArray[numBytes];
  char temp[3];
  Serial.begin(115200);
  Serial.println("starting");

  //convert 2 byte hex char nibbles to hex value
  for (byte i = 0; i < strlen(command); i += 2)
  {
    strncpy(temp, &command[i], 2);
    temp[2] = '\0'; //null terminate to use strtol()
    byte val = strtol(temp, NULL, 16);
    Serial.println(val, HEX);
    byteArray[i / 2] = val;
  }
  Serial.println("...........");

  Serial.write(byteArray, numBytes); //not readable characters

  //confirm data is in byteArray
  Serial.println();
  for (byte j = 0; j < numBytes; j++)
  {
    Serial.print(byteArray[j], HEX);
    if (j < numBytes - 1)
      Serial.print(',');
  }
  Serial.println();
}
void loop() {
}

i see no need to store "commands" on an SD card the same way they are communicated.

arrays can be stored in sequential memory by preceding each array with the length of the array stored as raw data bytes. the length, presumably followed by a command (or type) allows arrays to be relatively easily searched/skipped to locate commands matching a specific value

SOLVED, thanks cattledog
after fiddling around with the Serial.print and the SoftwareSerial stuff, I got it working as supposed (exept that the command will be send twice, which is no problem at the actual state of the project.
For further reference I'll post my final code here.

/* TMCL-SEND5.ino
 *  BRIEF: gets a hex value and converts it to be send over serial interface
 *  in my case the data should be send via an RS485pcb to a 
 * TRINAMIC Steprocker motor controller
 *  SoftwareSerial is used as the program will get bigger when finished
 *  maybe requiring an Arduino Mega.
 *  Thanks to the arduino forum's cattledog who pointed the right way
 *  2022-02-12
 */
#include <SoftwareSerial.h>
#define TX_ENABLE_PIN 2     // define the EIA-485 transmit driver pin ( RE + DE pin's modules)
SoftwareSerial rs485(2, 3); // SoftwareSerial rs485(RO, DI); pins name on the module

void setup() {
  pinMode(TX_ENABLE_PIN, OUTPUT);  // driver output enable
  rs485.begin (57600);              
  
  //char allcommands[50][24] = {"0A0100000000FA0005"}; // array of motorcommands and other data. To be filled from SDcard
  char command[19]={"0A0100000000FA0005"}; // for testing purpose command "rotate right" 
  byte numBytes = (sizeof(command) - 1) / 2; //one byte per 2 hex chars need sizeof() for constant array bound
  byte byteArray[numBytes];
  char temp[3];
 
 digitalWrite (TX_ENABLE_PIN, HIGH);
/* ****************** THIS IS THE IMPORTANT FUNCTION ************/
  for (byte i = 0; i < strlen(command); i += 2){
    strncpy(temp, &command[i], 2);
    temp[2] = '\0'; //null terminate to use strtol()
    byte val = strtol(temp, NULL, 16);
    byteArray[i / 2] = val;
  }
  digitalWrite (TX_ENABLE_PIN, LOW);
// Uncomment next line to let the motor rotate right
//rs485.write(byteArray, numBytes);
 
}
void loop() {;
}

My code-snipped only shows 1 command, the final program shall handle 50+ commands and other data which have to be editable without the use of the arduino ide.