Giter Site home page Giter Site logo

Comments (8)

soundanalogous avatar soundanalogous commented on July 17, 2024

Something like this should work. _WIN32 for be for any compiler on the Win32 platform (MSVC, MinGW, etc). If the problem is only related to the MSVC compiler, then it would be #ifdef _MSC_VER.

#ifdef _WIN32
strrchr(name, '') + 1;
#else
strrchr(name, '/') + 1;
#endif

.hc

from arduino.

soundanalogous avatar soundanalogous commented on July 17, 2024

How to handle 64-bit Windows?

from arduino.

basile-laderchi avatar basile-laderchi commented on July 17, 2024

On the work_machine (see P.S.) this code is not working:

#if defined WIN32 || defined WIN64 || defined _WIN32 || defined _WIN64 || defined __CYGWIN__ || defined __MINGW32__
  filename = strrchr(name, '\\') + 1;
#else
  filename = strrchr(name, '/') + 1;
#endif

The only thing that **worked** was replacing this:

filename = strrchr(name, '/') + 1;

with this:

filename = strrchr(name, '\\') + 1;

As for 64-bit Windows I found this: According to [msdn](http://msdn.microsoft.com/en-us/library/b0084kay.aspx) the _WIN32 should be "Defined for applications for Win32 and Win64. Always defined.", but this "Most compilers targeting Microsoft Windows implicitly define _WIN32.[1] This allows code, including preprocessor commands, to compile only when targeting Windows systems. A few compilers define WIN32 instead. For such compilers that do not implicitly define the _WIN32 macro, it can be specified on the compiler's command line, using -D_WIN32." [Wikipedia](http://en.wikipedia.org/wiki/C_preprocessor#Conditional_compilation) has to be taken into consideration too.

basile

P.S.: I have in my possession two machines:
home_machine: Win7 32bit with VS2010 and arduino v1.0 and
work_machine: Win7 64bit with VS2010 and arduino v1.0.

from arduino.

soundanalogous avatar soundanalogous commented on July 17, 2024

would something like this work?

if (strrchr(name, '/') != NULL) filename = strrchr(name, '/') + 1;
else filename = strrchr(name, '\\') + 1;

from arduino.

basile-laderchi avatar basile-laderchi commented on July 17, 2024

It works.
My Firmata.cpp has the following change and is reporting back "StandardFirmata" v2.3 (with StandardFirmata.ino loaded on the Arduino):

  if (strrchr(name, '/') != NULL)
    filename = strrchr(name, '/') + 1; //points to slash, +1 gets to start of filename
  else
    filename = strrchr(name, '\\') + 1; //points to backslash, +1 gets to start of filename

basile

from arduino.

adamlast avatar adamlast commented on July 17, 2024

I found I had to do this as well on my Win7 64 bit machine. This is an issue that's be known about for 5 months but not fixed.

Is it actually really sensible to generate the Firmware string dynamically during run time based on file name? What are the advantages?

from arduino.

kisoft avatar kisoft commented on July 17, 2024

I edited a method "setFirmwareNameAndVersion":

void FirmataClass::setFirmwareNameAndVersion(const char *name, byte major, byte minor)
{
  const char *filename;
  const char *extension;
  int len;

  extension = strrchr(name,'.');
  filename = strrchr(name,'/');
  if(!filename)
  {
    filename = strrchr(name,'\\');
  }
  if(!filename)
  {
    filename = name;
  }
  else
  {
    filename++;
  }
  if(!extension)
  {
    len =strlen( filename );
  }
  else
  {
    len = extension - filename;
  }
  firmwareVersionCount = len + 2;
  firmwareVersionVector = (byte *) malloc(firmwareVersionCount+1);
  firmwareVersionVector[0] = major;
  firmwareVersionVector[1] = minor;
  strncpy((char*)firmwareVersionVector + 2, filename, len);
  firmwareVersionVector[firmwareVersionCount] = '\0';
}

It's worked on my MSVC 2010 and Arduino Leonardo.
Good Luck!

from arduino.

soundanalogous avatar soundanalogous commented on July 17, 2024

updated in dev branch

from arduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.